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 to an unaligned address


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


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