llvm / llvm/llvm-project

[DFAJumpThreading] Wrong code at -O2 on x86_64-linux-gnu

Open
#211,090 8 comments 0 reactions 0 assignees View on GitHub
confirmed generated by fuzzer llvm:optimizations miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/7h1x8MG16
Testcase:
```c
#include
int16_t g5, g8 = 81;
void *g15;
_Bool f32_c2, f32_c8;
void __attribute__((noinline)) f7() { g5 = 25591; }
void __attribute__((noinline)) f32()
{
int64_t v1;
int16_t v5;
int16_t ov7 = 0;
v1 = g8;
lbl_br18:
f32_c2 = v1;
f7();
lbl_cont21:
if (f32_c2)
{
v5 = 0;
lbl_br30:
if (v1 == 702045342818) goto lbl_sw35;
}
lbl_b38:
f32_c8 = v5;
v1 = (char *)g15 - (char *)ov7;
if (f32_c8) return;
ov7 = g5;
switch (ov7)
{
case 6: goto lbl_br18;
case 25591: v5 = ~v5; goto lbl_b38;
default:
v5 = v1;
switch (v1)
{
case 8: goto lbl_sw35;
case 409861780891430: goto lbl_br30;
case 304994244176: goto lbl_cont21;
}
__builtin_unreachable();
}
lbl_sw35:
g5 = v5;
goto lbl_cont21;
}
int main() { f32(); }
```

This case hangs at -O2, and terminates at -O0.

Contributor guide

Open the contributing guide

Research direction

Compile the provided C testcase and compare its behavior at -O0 and -O2, using the linked Godbolt reproducer as the starting point. Investigate the DFAJumpThreading optimization named in the issue; done means the testcase no longer hangs at -O2 and retains the terminating behavior seen at -O0.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.