| Issue |
244616
|
| Summary |
[LoopDeletion] Segfault at -O1 and above in breakLoopBackedge (BasicBlock::getTerminator) on a loop containing an indirect goto
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
haoxintu
|
## Description
```c
int a, b;
void c() {
unsigned d;
while (1) {
if (__builtin_expect(0 >= d, 1))
break;
&&e;
e:
b++;
if (__builtin_expect(a, 0))
continue;
void *f[] = {&&g};
goto *f;
g:
d--;
}
}
```
```
$ clang -O1 -c repro.c # also -O2, -O3, -Os; -O0 is fine
PLEASE submit a bug report ...
3. Running pass "require<globals-aa>,..."
5. Running pass "loop(loop-idiom,indvars,loop-deletion,loop-unroll-full)" on function "c"
#5 llvm::BasicBlock::getTerminator() const
#6 llvm::breakLoopBackedge(llvm::Loop*, llvm::DominatorTree&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::MemorySSA*)::'lambda'()::operator()() const
#7 llvm::breakLoopBackedge(llvm::Loop*, llvm::DominatorTree&, llvm::ScalarEvolution&, llvm::LoopInfo&, llvm::MemorySSA*)
#8 llvm::LoopDeletionPass::run(...)
Segmentation fault
```
(The program reads `d` uninitialized and jumps through the array's own address. It is a reduced test case; only the compile matters here.)
`opt -O1` crashes on this reduced IR (llvm-reduce) as well. LoopDeletion run on its own does not crash, so the earlier -O1 passes are needed:
```llvm
@f0.tab_ = global [2 x ptr] [ptr inttoptr (i32 1 to ptr), ptr blockaddress(@f0, %if.end115)]
@f0.tab_.1 = global [2 x ptr] [ptr blockaddress(@f0, %while.cond117), ptr inttoptr (i32 1 to ptr)]
define i32 @f0(i32 %x, i32 %y) {
entry:
br label %while.cond
while.cond:
%s1.0 = phi i32 [ %y, %entry ], [ 0, %while.cond117 ]
%cmp = phi i1 [ true, %entry ], [ false, %while.cond117 ]
br i1 %cmp, label %while.body, label %common.ret
while.body:
%cmp30 = icmp eq i32 %y, %s1.0
br i1 %cmp30, label %common.ret, label %if.end115
common.ret:
%common.ret.op = phi i32 [ 0, %while.body ], [ %s1.0, %while.cond ]
ret i32 %common.ret.op
if.end115:
br label %while.cond117
while.cond117:
%cmp118 = icmp eq i32 %x, 0
br i1 %cmp118, label %while.body120, label %while.cond
while.body120:
indirectbr ptr null, [label %if.end115, label %while.cond117]
}
```
Reproduced in Godbolt (x86-64 clang assertions trunk, -O1): https://godbolt.org/z/aM9M95z77
## Checked Versions
- Segfault at -O1/-O2/-O3/-Os with clang trunk 2012344e5da8 (2026-11-19). -O0 is fine.
- clang 21.1.8 crashes the same way, so this is not a recent regression.
Thanks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs