[LLVMbugs] [Bug 510] NEW: [llvmgcc] bitfields bite again

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Feb 13 21:36:15 PST 2005


           Summary: [llvmgcc] bitfields bite again
           Product: tools
           Version: 1.0
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: llvm-g++
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sabre at nondot.org

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
        movl 4(%esp), %eax
        orl $1, 4(%eax)
        movw $123, 10(%eax)

And GCC produces this:

$ gcc ~/t.cc -S -o - -fomit-frame-pointer -O3
        movl    4(%esp), %eax
        orb     $1, 4(%eax)
        movw    $123, 6(%eax)

... note the differing offsets.

This is probably related to Bug 269 and Bug 285.


------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.

More information about the llvm-bugs mailing list