The following transcript shows llvm-gcc failing on input that gcc 4.0.4 compiles correctly. [reid@bashful C++Frontend]$ cat 2007-05-15-FieldAccess.cpp #include <stdio.h> class bitFieldStruct { public: int i; unsigned char c:7; int s:17; char c2; }; int main() { printf("sizeof(bitFieldStruct) == %d\n", sizeof(bitFieldStruct)); if (sizeof(bitFieldStruct) != 2 * sizeof(int)) printf("bitFieldStruct should be %d but is %d \n", 2 * sizeof(int), sizeof(bitFieldStruct)); bitFieldStruct x; char* xip = (char*) &x.i; char* xc2p = (char*) &x.c2; printf("Offset bitFieldStruct.i = %d\n", xip - xip); printf("Offset bitFieldStruct.c2 = %d\n", xc2p - xip); return 0; } [reid@bashful C++Frontend]$ /proj/llvm/cfe/install-2/bin/llvm-gcc -o doit 2007-05-15-FieldAccess.cpp -lstdc++ cc1plus: ../../src-2/gcc/llvm-convert.cpp:5583: LValue TreeToLLVM::EmitLV_COMPONENT_REF(tree_node*): Assertion `BitStart == 0 && "It's a bitfield reference or we didn't get to the field!"' failed. 2007-05-15-FieldAccess.cpp: In function 'int main()': 2007-05-15-FieldAccess.cpp:18: internal compiler error: Aborted [reid@bashful C++Frontend]$ gcc -o doit 2007-05-15-FieldAccess.cpp -lstdc++ [reid@bashful C++Frontend]$ ./doit sizeof(bitFieldStruct) == 8 Offset bitFieldStruct.i = 0 Offset bitFieldStruct.c2 = 7
Test case is in test/C++Frontend/2007-05-15-FieldAcces.cpp http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070514/049620.html
From Duncan Sands: IMHO both assertions are symptoms of ConvertRECORD breakage. Duncan also reported this assertion: LLVM type size doesn't match GCC type size! on a similar test case.
Created attachment 844 [details] Test case for this problem. This is a deja-gnu ready test case, the same as in the initial comment on this PR.
Also, when fixed, the testcase should go in llvm-test, not dejagnu.
I can make the test case deja-gnu compatible (doesn't execute). I'll do this sometime soonish.
maybe Duncan has an idea about this one
Here, the 32bit int field is used for 'c' and 's'. However it has enough bits (8) available for 'c2', so there is not any need to allocate another field.
This compiles to something sensible looking with llvm-gcc-4.2.