------- Comment #10 from joseph at codesourcery dot com  2009-04-29 11:33 
-------
Subject: Re:  [4.5 Regression] Revision 146817 caused
 unaligned access in gcc.dg/torture/pr26565.c

On Wed, 29 Apr 2009, matz at gcc dot gnu dot org wrote:

> The user should have the possibility to announce the unalignedness to the
> compiler via casts, like so:
> 
>   memcpy((char*)&outdata->tv, tp, sizeof outdata->tv);
> 
> (or void* or whatever).  This doesn't work currently, as the emitted gimple
> code loses that cast.
> 
> So, there're two things: explicit alignment changing casts are lost and
> the type of ADDR_EXPR of non-naturally aligned fields has the wrong pointer
> type (losing the unalignedness).
> 
> The former problem is a bit problematic to solve, as parameter passing
> always has an implicit conversion to the formal parameter type (void* in this
> case).  We don't want to lose alignment info just because of that conversion,
> only for explicit ones.

In ISO C terms casts change alignment information in the opposite 
direction to the one you want - if the conversion sequence contains 
anywhere a pointer to an N-byte aligned type, you can assume that the 
pointer is N-byte aligned, so you take the highest alignment from the 
sequence of types, not the lowest.  The problem is representing the 
address of an unaligned field as a pointer-to-aligned-type.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39954

Reply via email to