llvm / llvm/llvm-project

[Alias Analysis] Bad alias analysis with `setjmp`/`longjmp`

Open
#198,967 12 comments 0 reactions 1 assignee Claimed by @midhuncodes7 View on GitHub
llvm:analysis miscompilation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

In the following, Clang at `-O2` omits the write of `13` to `i` without regard for the fact that `*p` can point to `i`. GCC does not have this issue (even at `-O3`).

https://godbolt.org/z/e19zKbrPj

#### Source (``):
```c
#include
int x, ii;
jmp_buf buf;
void redo();
void bar() {
int *volatile p;
int i;
setjmp(buf);
if (x) {
p = &i;
redo();
}
else {
i = 13;
ii = *p;
}
}
```

#### Compiler invocation:
```
clang --target=x86_64-unknown-linux-gnu -O2 -S -o - -xc -
```

#### Actual output:
(assembly has no instance of `movl $13, `)

#### Expected output:
(assembly contains `movl $13, `)

#### Compiler version info (`clang -v` output):
```
clang version 23.0.0git (https://github.com/llvm/llvm-project.git e8c6318c2a07f8eb4643db610854b0e993a4ed6e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/14
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

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.