<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 - Infinite loop at -O2 and above at compile-time on clang 12.0.x to trunk version"
   href="https://bugs.llvm.org/show_bug.cgi?id=51657">51657</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Infinite loop at -O2 and above at compile-time on clang 12.0.x to trunk version
          </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.

The following test program makes clang 12.0.x to trunk version hang on -O2 and
above.

$cat small.c
#include <stdint.h>
int a,b,c;
void d(int e) {
  int8_t *f;
  int16_t g;
  int32_t i = &a;
  uint16_t *j;
  int8_t *k = &c;
  int16_t l = 246;
  uint64_t m;
  int8_t **n = &k;
  int64_t o;
  int16_t *p;
  for (; p;) {
    int64_t *q = o;
    for (*q = 5; *q; *q += 1)
      if (*k = b)
        for (*j = 3; *j; j++) {
          int8_t r;
          o = r;
        }
    for (; p <= 2; p++)
    s:
      l = 1;
  }
  g = m = e;
  uint64_t v;
  int32_t **u = &i;
  uint64_t t = &v;
  f = *u;
  *f = c = l;
  v = (g ?: (**u = m << **n)) == *f;
  for (; i <= 8; *f = t)
    ;
  goto s;
}

$clang -w -O2 -m32 small.c
//endless compiling, same as -O3 and -Os

$time clang -c -w -O1 -m32 small.c

real    0m0.059s
user    0m0.028s
sys     0m0.031s


The clang version I used:
clang version 14.0.0 (<a href="https://github.com/llvm/llvm-project">https://github.com/llvm/llvm-project</a>
022538f2764a255bd2c0da3a247791e764933a93)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

Reproduced in Godbolt: <a href="https://godbolt.org/z/ndxn1cT91">https://godbolt.org/z/ndxn1cT91</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>