First Last Prev Next    No search results available
Details
: [llvmgcc] Field offset miscalculated for some structure f...
Bug#: 510
: tools
: llvm-gcc
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.5

:
: miscompilation
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2005-02-13 23:36
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
------- Comment #1 From Chris Lattner 2005-02-14 23:27:19 -------
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

First Last Prev Next    No search results available