This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: memcpy / Language Lawyer / optimization question


On Thu, 9 Dec 2004, Steve Ellcey wrote:

> My question is about the second memcpy where I cast to (void *).  This
> still results in an abort on IA64 because it is still assuming integer
> alignment (and thus changing the code to do an integer assignment).  Is
> it legal to do this transformation with the (void *) cast?

The casts in the calls to memcpy are irrelevant: the undefined behavior 
occurs before them, at the point where you cast an unaligned pointer to 
int *.  Casting a pointer to another pointer type for which it doesn't 
have the alignment yields undefined behavior.  The compiler can assume 
that the result of a sequence of pointer casts has the alignment of 
whichever type in the sequence of pointer types has the strictest 
alignment requirements.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]