Bugzilla – Bug 510
[llvmgcc] Field offset miscalculated for some structure fields following bit fields
Last modified: 2005-05-15 16:11:42
You need to log in before you can comment on or make changes to this bug.
This is the next miscompilation of QT4.0 that I hit: ---- struct QVectorTypedData { int size; unsigned int sharable : 1; unsigned short array[1]; }; void foo(QVectorTypedData *X) { X->sharable = 1; X->array[0] = 123; } ---- We compile this to: --- %struct.QVectorTypedData = type { int, int } implementation ; Functions: void %_Z3fooP16QVectorTypedData(%struct.QVectorTypedData* %X) { %tmp.1 = getelementptr %struct.QVectorTypedData* %X, int 0, uint 1 %tmp.4 = load int* %tmp.1 %tmp.5 = or int %tmp.4, 1 store int %tmp.5, int* %tmp.1 %tmp.10 = cast int* %tmp.1 to sbyte* %tmp.11 = getelementptr sbyte* %tmp.10, int 6[#uses=1] %tmp.13 = cast sbyte* %tmp.11 to [1 x ushort]* %tmp.14 = getelementptr [1 x ushort]* %tmp.13, int 0, int 0 store ushort 123, ushort* %tmp.14 ret void } --- This is one of those cases where it is easier to look at machine code. We produce this: $ llvm-gcc ~/t.cc -c -o - | llc -disable-pattern-isel=0 ... _Z3fooP16QVectorTypedData: movl 4(%esp), %eax orl $1, 4(%eax) movw $123, 10(%eax) ret And GCC produces this: $ gcc ~/t.cc -S -o - -fomit-frame-pointer -O3 _Z3fooP16QVectorTypedData: movl 4(%esp), %eax orb $1, 4(%eax) movw $123, 6(%eax) ret ... note the differing offsets. This is probably related to Bug 269 and Bug 285. -Chris
Fixed. Test here: test/Regression/C++Frontend/2005-02-14-BitFieldOffset.cpp Patch here: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20050214/024119.html -Chris