<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 - wrong code at -O2 and above on x86_64-linux-gnu (affecting clang-6.0 and above versions)"
   href="https://bugs.llvm.org/show_bug.cgi?id=52495">52495</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wrong code at -O2 and above on x86_64-linux-gnu (affecting clang-6.0 and above versions)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Hi all.

I guess the following program is well-defined but makes clang produce wrong
code across many versions.

$cat small.c
#include <stdio.h>
#include <stdint.h>

union a {
  int16_t b;
  uint64_t c;
} d;

uint64_t *e = &d.c;
static uint16_t f(int16_t a, int32_t b, uint64_t c);
static int64_t g(int32_t aa, uint8_t h, union a bb) {
  int16_t *i = &d.b;
  f(0, h, 0);
  *i = h;
  return 0;
}
uint16_t f(int16_t a, int32_t b, uint64_t c) {
  for (d.c = 0; 0;)
    ;
  *e = 0;
  return 0;
}

int main() {
  uint32_t j = 8;
  g(1, j, d);
  printf("%d\n", d.b);
  return 0;
}


$clang -w -O1 small.c ; ./a.out
8

$clang -w -O2 small.c ; ./a.out
0

$clang -w -O3 small.c ; ./a.out
0

$clang-5.0 -w -O small.c ; ./a.out
8

Please check more in Godbolt: <a href="https://godbolt.org/z/c3YzvYe7a">https://godbolt.org/z/c3YzvYe7a</a>

Thanks,
Haoxin</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>