llvm / llvm/llvm-project

[GlobalOpt] Wrong code at -O1 since clang-18

Open
#215,533 1 comment 0 reactions 1 assignee Claimed by @osa1 View on GitHub
generated by fuzzer llvm:optimizations miscompilation regression:18
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/vGEz9nxMM
Reduced case:
```c
#include
#include
typedef uint32_t v4u32 __attribute__((vector_size(16)));
_Bool g5;
static void *g10;
v4u32 g26;
int main()
{
uint32_t bb3;
g10 = aligned_alloc(_Alignof(v4u32), sizeof(v4u32));
*(v4u32 *)g10 = g26;
__builtin_memmove(&bb3, g10, 4);
g5 = bb3;
}
```

This case triggers SIGSEGV at -O1, and terminates normally at -O0.

A quick look into the final IR at -O1:
```llvm
@g26 = dso_local local_unnamed_addr global <4 x i32> zeroinitializer, align 16
@g5 = dso_local local_unnamed_addr global i8 0, align 1
@g10.body = internal unnamed_addr global [16 x i8] undef, align 4

define dso_local noundef i32 @main() local_unnamed_addr {
entry:
%0 = load <4 x i32>, ptr @g26, align 16
store <4 x i32> %0, ptr @g10.body, align 16
%bb3.0.copyload = load i32, ptr @g10.body, align 16
%tobool = icmp ne i32 %bb3.0.copyload, 0
%storedv = zext i1 %tobool to i8
store i8 %storedv, ptr @g5, align 1
ret i32 0
}
```
It seems that the object returned by `aligned_alloc` is transformed into a global aligned with 4. But the accesses to it are still aligned with 16.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.