Union aliasing issue in clang 3.3 on FreeBSD

Hi,

I encountered a union aliasing issue on FreeBSD clang 3.3, see code
below. In short, assigning a union value to another when the union
contains a double and an array of 8 bytes causes the value to copy
incorrectly. This is dependent on compiler options, the behavior
doesn't happen without -m32 or when using -O0. It also doesn't happen
with an older clang.

Is this a clang issue, or is my code making invalid assumptions about
unions and casting? Based on a quick look at the generated asm code,
clang generates a floating point load/store to copy the value - could
this be the root cause? The code looks something like:

8048653: dd 44 24 20 fldl 0x20(%esp)
8048657: dd 5c 24 10 fstpl 0x10(%esp)
804865b: 8d 44 24 10 lea 0x10(%esp),%eax
804865f: 89 04 24 mov %eax,(%esp)
8048662: e8 61 ff ff ff call 80485c8 <dump>

Thanks for any help :slight_smile: I'm pasting the code below as I'm not sure
whether or not attachments are supported.

======== clang_aliasing.c
/*
* Problem with clang 3.3 on FreeBSD: