<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 error"
   href="https://bugs.llvm.org/show_bug.cgi?id=41764">41764</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wrong code error
          </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>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>new bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I am not sure whether it is a bug. Maybe it is an undefined behaviour. I cannot
understand why the results are different at different optimization level.
Specially, if I change the int64_t to type int, the bug doesn't exist.

<span class="quote">> cat report.c</span >
typedef char int8_t;
typedef int int16_t;
typedef int uint16_t;
typedef long int64_t;
typedef char uint8_t;
typedef int uint32_t;

union a {
  int64_t b;
  uint16_t c;
} e;
int8_t d, l, h;
uint16_t *g = &e.c;
uint16_t **i = &g;
int16_t j;
uint16_t ***k = &i;
uint32_t m();
int8_t *n(uint16_t, uint32_t, uint16_t, union a, uint32_t);
uint32_t o() {
  union a p = {};
  m(n(d, 0, 0, p, d));
  return l;
}
uint32_t m() {
  int64_t *ad = &e.b;
  *ad = 0;
  int16_t *ae = &j;
  *ae = ***k;
  return h;
}
int8_t *n(uint16_t f, uint32_t ag, uint16_t ah, union a ai, uint32_t aj) {
  int8_t *ak = &d;
  (***k)++;
  return ak;
}
int main() {
  o();
  printf("%d\n", j);
}

<span class="quote">> clang -v </span >
clang version 9.0.0 (trunk 356835) (llvm/trunk 356836)
......

<span class="quote">> clang report.c -O0 -o a0
> clang report.c -O2 -o a2
>./a0</span >
0
<span class="quote">>./a2</span >
1</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>