llvm / llvm/llvm-project

Wrong code at -O3 on x86

Open
#224,200 1 comment 0 reactions 1 assignee Assigned to @slant14 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/8YPjcbbqP
Reduced case:
```c
#include
typedef uint8_t v32u8 __attribute__((vector_size(32)));
typedef uint32_t v32u32 __attribute__((vector_size(128)));
_Bool g1;
v32u32 g2;
v32u8 g4;
uint32_t g9 = 2217788559;
volatile uint32_t g11 = 3809015228;
uint16_t g14;
__attribute__((__vector_size__(8 * sizeof(int)))) int f3_a2;
void f3()
{
v32u32 vec8;
lbl_f3_b0:
if (g14) g11;
if (g1) return;
g2 = vec8;
vec8 = __builtin_convertvector(g4, v32u32);
vec8[__builtin_clz(f3_a2[2])] = 5;
goto lbl_f3_b0;
}
int main()
{
uint32_t ov2;
g1 = __builtin_add_overflow(g11, g9, &ov2);
f3();
}
```

This case triggers SIGBUS at -O3, and terminates normally at -O0.

Contributor guide

Open the contributing guide

Research direction

Start by running the Godbolt reproducer and the reduced C case on x86 at -O0 and -O3, then trace where the optimized behavior diverges. Done means the optimized case no longer triggers SIGBUS and the reduced behavior is covered by a regression check.

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
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.