[Clang] Wrong code at -O1 on x86_64-linux_gnu
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Compiler Explorer: https://godbolt.org/z/38G7fYeco
- fail: trunk, 22, 21, 20, 19, 18
- work: 17.0.1 and earlier
Bisected to [d218092](https://github.com/llvm/llvm-project/commit/d218092543b3f9ba2204d7c8fe5ac70befa3d772), which is committed by @dtcxzyw.
small.c
```c
int a, d, f;
long long c[5];
int g(short h) {
long e = h & 1048575;
switch (e)
case 4:
case 6:
for (;;)
;
return 0;
}
long i(long long *h, long j) {
for (int k = 0; k < 5; k++) {
int b = h[k] ^ j;
switch ((b + a - 50) % 6u) {
case 3:
d += 5;
break;
case 0:
d = b + 7080;
d = g(b + 050) + b + j + b * 3;
case 5:
f = 1;
case 1:
d = b + b;
case 2:
case 4:
d ^= 3;
}
a = 50;
}
return d + j + d + ((char)(d + 7) + d - 3) + f;
}
int main() { i(c, -976002); }
```
Reproduce:
```
$ clang-trunk -O0 small.c && ./a.out
$ clang-trunk -O2 small.c && ./a.out
$ clang-trunk -O1 small.c && ./a.out
[1] 3335073 segmentation fault (core dumped) ./a.out
```
Contributor guide
Research direction
Start with the small.c reproducer and compare its behavior when compiled with clang-trunk at -O0, -O1, and -O2. Investigate the bisected commit d218092 and the optimization path used at -O1. Done means the reproducer no longer produces a segmentation fault with the affected compiler versions, with regression coverage added where appropriate.
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
- 45/100