[cfe-dev] Possible clang bug with aligned structs

Matt Arsenault arsenm2 at rpi.edu
Mon Oct 18 16:32:07 PDT 2010


I've found a problem where clang generates code which crashes. The simplest case seems to happen when trying to use a vector type or aligned struct in a struct with the aligned and packed attributes, where the first item in the struct is smaller than the aligned struct. On assignment to the vector field, 	the program crashes with gdb reporting it as "Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x0000000000000000"

The reduced test case crash occurs when building WITHOUT optimizations (i.e. -O0), but doesn't with higher levels (-O1, -O2, or -O3). However, in the larger program I was working with when I encountered the problem, it was broken with and without optimizations. Both the test case and the program I was working on worked fine with gcc and llvm-gcc.

Both lldb and gdb are terribly confused in functions where this problem occurs, reporting wrong values for the arguments passed in which don't agree with values printed out.

Attached is a small test case. It consists of 4 variants on the same concept, with some more notes about what I've found about the problem. With any of the special vector extension types, or the struct with the aligned attribute, clang generates code which crashes when assigning to that field within the larger struct. Tested on x86_64 Linux and OS X, clang 2.8, and gcc-4.5, and (GCC) 4.2.1 (Apple Inc. build 5664).

Build / run it with:  

$ clang -O0 aligned_struct_bug.c && ./a.out
-------------- next part --------------
A non-text attachment was scrubbed...
Name: aligned_struct_bug.c
Type: application/octet-stream
Size: 2919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101018/b8bedcb3/attachment.obj>


More information about the cfe-dev mailing list