* Tom Lane:

> I ran into an interesting failure here on HPPA: the code the compiler
> generated for copying unaligned toast pointers into aligned local
> variables failed, because it was assuming halfword (2-byte) alignment of
> the data to be copied!  (Instead of a memcpy call it was generating an
> inline loop of ldh/sth instructions.)  Apparently gcc's thought process
> is "the pointer is declared as struct varlena *, therefore must be at
> least 4-aligned, therefore the data at offset 2 is at least 2-aligned".
> The intermediate cast to "varattrib_1b_e *" did not prevent this; I
> had to assign the datum pointer into a separate local variable of that
> type to suppress the "optimization".

This is quite deliberate, it leads to better code.  In general, once
you've cast a pointer to something which needs more alignment than
what's actually, there is no way to get away from that (except using
asm insertions as optimization barriers, of course).  This is fine
from the C semantics because undefined behavior occurs during the cast

I believe that other compilers have similar rules (certainly when it
comes to aliasing), so it's better not to try to outsmart the C
standard here.

Florian Weimer                <[EMAIL PROTECTED]>
BFK edv-consulting GmbH       http://www.bfk.de/
Kriegsstra├če 100              tel: +49-721-96201-1
D-76133 Karlsruhe             fax: +49-721-96201-99

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?


Reply via email to