<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -O0 bug: long bitfields triggering incorrect code"
   href="https://bugs.llvm.org/show_bug.cgi?id=35763">35763</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-O0 bug: long bitfields triggering incorrect code
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>babokin@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>clang trunk, x86_64, rev321482.

<span class="quote">> cat f.cpp</span >
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;
}

<span class="quote">> clang++ -w f.cpp -o outc; g++ -w f.cpp -o outg; ./outc; ./outg</span >
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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>