<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63640>63640</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            wrong-code at -O1 and above on clang-11
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          haoxintu
      </td>
    </tr>
</table>

<pre>
    Hi, please consider the following code `small.c`:

```
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

union a {
 uint16_t b;
} m = {.b=0};
int8_t c[6][1] = {0};
int16_t *d = 0;
int ids = 0;
void __attribute__((noinline)) marker_1() { printf(" b%db ", 1); ids++; }
uint16_t e(int16_t, union a);
union a f(uint64_t, int32_t, int8_t, int16_t *, uint32_t);
static uint16_t g(int8_t *);
int8_t *h();
uint16_t i() {
  int16_t j = e(0, f(c[5][0], c[1][0], 0, d, c[1][0]));
  return j;
}
uint16_t e(int16_t k, union a l) { return l.b; }
union a f(uint64_t n, int32_t u, int8_t o, int16_t *p, uint32_t s) {
  g(h());
  return m;
}
uint16_t g(int8_t * a) {
  marker_1();
  return 0;
}
int8_t *h() {
  int q = 0;
r:
  for (; q <= 5; q++) {
    uint8_t t;
    if (q)
 goto r;
  }
  return 0;
}
int main() { i(); printf("%d\n", ids);}
```

```
$clang-11 -w -O1 -std=c99 small.c ; ./a.out
 b1b 1
$clang-11 -w -O0 -std=c99 small.c ;./a.out
(hang)
$clang-11
clang version 11.1.0 (https://github.com/llvm/llvm-project 1fdec59bffc11ae37eb51a1b9869f0696bfd5312)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/haoxin/haoxin-data/compilers/llvm-project/build-clang-11/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
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/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/lib/cuda, version 10.1
```

It seems the `goto-loop` in function `h` is removed with higher optimization (-O1 and above) on clang-11. May I know what could be the reasons behind this?

See the demo in Godbolt: https://godbolt.org/z/G85dsKxT1

Thanks,
Haoxin

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VkFv2zgT_TX0ZWBBJCVZOvgQ25_a4sNiD-2eDYqkLTYU6YpUkvbXL0jJiuImKRZogcCiyJk3b95wJmLOqbORcovyHcoPKzb41vbbltknZfywaqz4vv2oENnDRUvmJHBrnBKyB99KOFmt7aMyZ-BWSEBF6jqmdcJRkSJ6h9IDSq-_RTr9ja-EKsP1ELzo3nmhjE9aRP_3xrFWzXvHyi5P4-9glDXAAG124wYMynhcHD00iE57aHOADhA9BLOkQfSQos1hPlbGl0cPHOW7AuUHlO8wyg9X-1vTiI3InYgG6fIIlHA3uw9WCTgemfe9agYvj0dESkRKY5XRykhEKkQq6Fh_L_sjjodVCAuXXhl_ihsEGkRy0QAiJBQJBy-6C-EQ2YU_uoNAc5TkSlIiUk7r4DVJNfq-VC-ECW5FNpoq4ymZl-W8uuYe4WajZzznmVf8uQTnkUF59apuNUfkrh1zfuZ0dVbPYkylnSl8jSqH_NJAJdAP1cvH6qXhQfaxoPjlVjQXrx5WSxIAvfRDb-Dr8hK9rS_cLxQGfa3hBKLDnVtW6BXZwSyEh-FZerA34l-W6oO7kShIfpX0tYS6dxJ6Wa54VZbQLy_pz9Dpz9A_lfmmmvDtpl_6eaAAnGwPwYvuotk-WObxbbr1L-EgihLC-QU3AHUKKN8C5XHvbL2FfmEz0_1FKtAxZRYtqmYl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