This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: memcpy to an unaligned address
- From: Ian Lance Taylor <ian at airs dot com>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: mrs at apple dot com (Mike Stump), dave dot korn at artimi dot com (Dave Korn), pkoning at equallogic dot com (Paul Koning), gcc at sources dot redhat dot com, sjackman at gmail dot com (Shaun Jackman)
- Date: 02 Aug 2005 13:45:01 -0700
- Subject: Re: memcpy to an unaligned address
- References: <200508022037.j72Kbr4T012558@earth.phy.uc.edu>
Andrew Pinski <pinskia@physics.uc.edu> writes:
> > Yes, this is a compiler bug in the expansion of memcpy, please file a
> > bug report. The solution is for the compiler to notice the memory
> > alignment of the destination and `do-the-right-thing' when it isn't
> > aligned.
>
> No it is not, once you take the address (which should be rejected), it
> is of type "unsigned int *" and not unaligned variable, passing it to
> memcpy assumes the type alignment is the natural alignment.
That argument doesn't make sense to me. memcpy takes a void*
argument, which has no presumed alignment. The builtin should work
the same way. That is, there is an implicit cast to void* in the
argument to memcpy. The compiler can certainly take advantage of any
knowledge it has about the alignment, but it can't assume anything
about the alignment that it doesn't already know.
Ian