[llvm-commits] [PATCH] Fix Alias Bug

Stephen Canon scanon at apple.com
Tue Jan 8 14:30:25 PST 2013


On Jan 8, 2013, at 4:51 PM, dag at cray.com wrote:

> David Blaikie <dblaikie at gmail.com> writes:
> 
>> General feedback: please send all patches for review as attachments,
>> not inline, so that mail clients don't mangle your patches.
> 
> Ok, will fix the git config.
> 
>> It's still UB to access the non-active member of a union. I believe
>> the only valid way to do this sort of thing is with memcpy (you're
>> allowed to read/write the bytes of such simple types through char*s) &
>> let the compiler optimize that into the same trivial copy.
> 
> Hmm.  Are you use this is UB?  It's the technique "everyone" seems to
> recommend.  Unfortunately, I recently recycled my copy of the standard
> in favor of the AVX2 spec.  :)

For C, footnote 95 says the following:

If the member used to read the contents of a union object
is not the same as the member last used to store a value
in the object, the appropriate part of the object representation
of the value is reinterpreted as an object representation in the
new type as described in 6.2.6 (a process sometimes called
‘‘type punning’’). This might be a trap representation. 

I am not aware of any similar language for C++, though I don't know the C++ standard nearly as well.  Either way, memcpy( ) is unambiguously correct and should generate good code.

- Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130108/28789c6c/attachment.html>


More information about the llvm-commits mailing list