| Issue |
243095
|
| Summary |
[AArch64][MachineSink] clang -O1 crashes with Segmentation fault in "Machine code sinking" on pointer arithmetic + switch
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
HG-Wang
|
### Summary
clang crashes with a segmentation fault in the backend `Machine code sinking` pass at `-O1` on aarch64. Reproduced with clang 23.1.6. The same source compiles cleanly with gcc, and with clang for x86_64 / armv7.
### Version
- clang 23.1.6 (`++20261108033755+c47d7823685a-1~exp1~20261108153854.96`)
- Target: `aarch64-unknown-linux-gnu`
### Reproducer
```c
int a;
void c(int d, long e) {
int f = -1;
char *g = (char *)(f + (int)e - -1) + e;
if (a)
a = 0;
switch (d)
case 1:
g[0] = 0;
}
void h(int i) { c(i, (long)i - 53); }
long j;
void k() { h((int)j + 53); }
```
`clang -O1 -c repro.c` → Segmentation fault.
### Crash output
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /usr/lib/llvm-23/bin/clang -cc1 -triple aarch64-unknown-linux-gnu -O1 -emit-obj ...
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'repro.c'.
4. Running pass 'Machine code sinking' on function '@k'
#0 0x... llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
#1 0x... llvm::sys::RunSignalHandlers()
...
clang: error: unable to execute command: Segmentation fault
```
### Scope
| target | -O0 | -O1 | -O2 | -O3 |
| --- | --- | --- | --- | --- |
| aarch64-linux-gnu | ok | **crash** | ok | ok |
| x86_64-linux-gnu | ok | ok | ok | ok |
| armv7-linux-gnueabihf | ok | ok | ok | ok |
- `clang -O1 -emit-llvm -S` succeeds, so this is a backend (code generation) bug rather than a middle-end one.
- gcc 16.1.0 compiles the same source without error.
### Relation to existing reports
- #187785 ([AArch64][MachineSink] Clang crashes at -O1/2/3/s on aarch64: Segmentation fault in machine code sinking) was fixed by #188048 ("Prevent attempts to sink-and-fold into the same instruction more than once"). The reproducer from #187785 does **not** crash with clang 23.1.6, so this looks like a different trigger in the same pass rather than that fixed bug.
- #216632, #216742 and #216870 (MachineSink crashes involving undef registers) are already included in 23.1.6 and do not cover this case.
Found by compiler fuzzing with synthesized C programs.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs