[llvm-bugs] [Bug 35763] New: -O0 bug: long bitfields triggering incorrect code

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 28 02:40:46 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35763

            Bug ID: 35763
           Summary: -O0 bug: long bitfields triggering incorrect code
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: babokin at gmail.com
                CC: llvm-bugs at lists.llvm.org

clang trunk, x86_64, rev321482.

> cat f.cpp
struct S {
    short m0;
    unsigned long long int m2 : 21;
    short m3 : 16;
    short m5 : 17;
    short : 16;
};

S z = {-724, 388702ULL, 26720, 2792};

unsigned long long int tf_3_var_136 = 0;

void foo() {
  tf_3_var_136 = ((unsigned short)(z.m0 | z.m2));
  z.m5 = 0;
}

int main() {
    foo();
    __builtin_printf("%llu\n", tf_3_var_136);
    return 0;
}

> clang++ -w f.cpp -o outc; g++ -w f.cpp -o outg; ./outc; ./outg
3999203198
65406

Note that clang 5.0 also produces correct result (as gcc in the example above).

Slight massaging of the test case make the bug go. You may notice that one of
the bit fields is longer than "base" type, i.e. short : 17. But this is a valid
C++, according to the standard bits after the "base" type size are just
"padding".

Anyway, effects triggered by this example are definitely considered as a bug by
regular clang users.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171228/2104bd97/attachment.html>


More information about the llvm-bugs mailing list