title: Why are the results of this code different with and without "-fsanitize=undefined,address"?
body: <p>I found that this code produces different results with &quot;-fsanitize=undefined,address&quot; and without it.</p>
  <pre><code>int printf(const char *, ...);
  union {
    long a;
    short b;
    int c;
  } d;
  int *e = &amp;d.c;
  int f, g;
  long *h = &amp;d.a;
  int main() {
    for (; f &lt;= 0; f++) {
      *h = g;
      *e = 6;
    }
    printf(&quot;%d\n&quot;, d.b);
  }
  </code></pre>
  <p>The command line is:</p>
  <pre><code>$ clang -O0 -fsanitize=undefined,address a.c -o out0
  $ clang -O1 -fsanitize=undefined,address a.c -o out1
  $ clang -O1 a.c -o out11
  $ ./out0
  6
  $ ./out1
  6
  $ ./out11
  0
  </code></pre>
  <p>The Clang version is:</p>
  <pre><code>$ clang -v
  clang version 13.0.0 (/data/src/llvm-dev/llvm-project/clang 3eb2158f4fea90d56aeb200a5ca06f536c1df683)
  Target: x86_64-unknown-linux-gnu
  Thread model: posix
  InstalledDir: /data/bin/llvm-dev/bin
  Found candidate GCC installation: /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7
  Selected GCC installation: /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7
  Candidate multilib: .;@m64
  Candidate multilib: 32;@m32
  Selected multilib: .;@m64
  Found CUDA installation: /usr/local/cuda, version 10.2
  </code></pre>
  <p>The OS and platform are:</p>
  <pre><code>CentOS Linux release 7.8.2003 (Core).0, x86_64 GNU/Linux
  </code></pre>
  <p>My questions:</p>
  <ol>
  <li>Is there something wrong with my code? Is taking the address of multiple members of the union invalid in C?</li>
  <li>If there is something wrong with my code, how do I get LLVM (or GCC) to warn me? I have used -Wall -Wextra but LLVM and GCC show no warning.</li>
  </ol>