This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy / Language Lawyer / optimization question
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: sje at cup dot hp dot com
- Cc: gcc at gcc dot gnu dot org
- Date: 09 Dec 2004 21:07:36 +0100
- Subject: Re: memcpy / Language Lawyer / optimization question
- Organization: Integrable Solutions
- References: <200412091932.LAA06762@hpsje.cup.hp.com>
Steve Ellcey <sje@cup.hp.com> writes:
| I have a question about memcpy and when it is legal to turn it into a
| simple assignment. The first memcpy in the program below will cause an
| abort on IA64 when compiled with -O2 because it gets turned into integer
| assignment and p is not properly aligned. I think this is OK. The last
| memcpy, where I put in a cast to (char *), will not assume any alignment
| and this compiles and runs correctly on IA64 with -O2. Again, I think
| this is OK.
|
| 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?
There is an explicit permission of copying an object into a possibly
non-aligned array of char or unsigned, with say memcpy(), and copy it
back with no problem.
I believe the rule
[#26] A pointer to void shall have the same representation
and alignment requirements as a pointer to a character
type.39) Similarly, pointers to qualified or unqualified
versions of compatible types shall have the same
representation and alignment requirements. All pointers to
structure types shall have the same representation and
alignment requirements as each other. All pointers to union
types shall have the same representation and alignment
requirements as each other. Pointers to other types need
not have the same representation or alignment requirements.
implies that any alignment derivation we make on char* shall also hold
for void*. In particular the use of void* should inhibit the
transformation of memcpy into an object assignment.
-- Gaby