Issue 240451
Summary [LoongArch] "error: Undefined temporary symbol .LJTI2_0" at -O1: the address of a jump table that is not emitted
Labels generated by fuzzer
Assignees
Reporter hazohelet
    Live Reproducer: https://godbolt.org/z/1d9qxa5WT

Compiling the following C code for `loongarch64` with `clang -O1` fails in the integrated assembler.

```c
int g(int, int);
int h(int, int);
int k(int, int);
signed char mul(signed char a, signed char b) {
  signed char r;
 return __builtin_mul_overflow(a, b, &r);
}
signed char m;
signed char f(signed char a) {
  signed char l = 0;
  switch (g(0, 0) & 3) {
  case 0:
    l = a;
  case 2:
    if (a)
      l = 0;
  case 3:;
  }
 return ~l;
}
signed char t;
signed char s;
int main(void) {
  signed char x = 0;
  int i;
  signed char *p = &x;
  switch (f(0)) {
  case 0:
 break;
  default:
    *p = 0;
  }
  t = mul(m, 5);
  h(t, x);
  for (i = 0; i < 8; i++)
    p = k(0, 0) ? p : 0;
  for (;;)
    s = x ? f(m) : *p;
}
```

clang command:

```sh
clang --target=loongarch64-linux-gnu -O1 -c repro.c
```

The compilation fails with the following output:

```text
error: Undefined temporary symbol .LJTI2_0
1 error generated.
```

`main` materializes the address of `.LJTI2_0` before its last loop, but the assembly defines only `.LJTI1_0`, the jump table of `f`:

```asm
# %bb.2:
        pcalau12i       $s1, %pc_hi20(s)
 pcalau12i       $a0, %pc_hi20(.LJTI2_0)
        addi.d          $s2, $a0, %pc_lo12(.LJTI2_0)
```

Notes:

* -O0 and -O2 compile it
* other archs (x86-64, aarch64) compile it at -O1
* Writing `case 3: break;` instead of `case 3:;` makes it compile

clang version:

```text
clang version 24.0.0git (https://github.com/llvm/llvm-project f5744e07d2dba7367ec68426fd6b6b07e2916b39)
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to