[llvm-commits] [PATCH] Fix Alias Bug
Richard Smith
richard at metafoo.co.uk
Tue Jan 8 15:18:50 PST 2013
On Tue, Jan 8, 2013 at 2:59 PM, <dag at cray.com> wrote:
> Stephen Canon <scanon at apple.com> writes:
>
>> 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 believe the C standard has also changed over the years, to the point
> where there's much confusion about this issue, according to the google.
> :)
This is UB in C++, but is given defined behavior as a GNU extension,
which Clang supports.
>> 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.
>
> I'm happy to use memcpy if that's what people want. Honestly, my goal
> was to make gcc shut up, not necessarily guarantee correctness, though
> this is a unit test. :)
memcpy is the "blessed" C++ approach for this.
More information about the llvm-commits
mailing list