Current-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: memcpy vs. gcc strict aliasing

On Wed, Dec 03, 2008 at 08:46:25AM +0200, Alan Barrett wrote:
> On Tue, 02 Dec 2008, David Laight wrote:
> > Recent versions of gcc will treat the memcpy the same as the structure
> > assignment! This means both 'suffer' from the 'strict aliasing'
> > optimisations.
> The part of the C99 standard that gives the aliasing rules (section 6.1
> paragraph 7 in the N1256 draft) allows any object to be accessed through
> a character type.  I'd argue that the text "the memcpy function copies
> n characters ..." in the definition of the memcpy function (section
> of the N1256 draft) means that memcpy is supposed to do its
> work using character types (even though the args are passed as void*
> pointers).  Given the implied use of character types, it seems to me
> that the use of memcpy should not lead to surprises traceable to the
> aliasing rules.  If the use of memcpy is leading to aliasing surprises,
> I'd argue that there's a compiler bug.

So would I ...

I just remember problems with sparc and the compiler assuming the
alignment constraints of the implied type when inlining memcpy().
Perhaps using the 'as if' rule to avoid doing the copy itself!


David Laight:

Home | Main Index | Thread Index | Old Index