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: unassignedb...@nondot.org
          Reporter: babo...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to