This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy / Language Lawyer / optimization question
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Steve Ellcey <sje at cup dot hp dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 9 Dec 2004 20:20:43 +0000 (UTC)
- Subject: Re: memcpy / Language Lawyer / optimization question
- References: <200412091932.LAA06762@hpsje.cup.hp.com>
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)