llvm / llvm/llvm-project

`-fsanitize=undefined` does not detect uninitialized lvalue

Open
#201,850 6 comments 0 reactions 0 assignees View on GitHub
compiler-rt:ubsan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

ISO C23 6.3.2.1p2 says: "If the lvalue designates an object of automatic storage duration that could have been declared with the register storage class (never had its address taken), and that object is uninitialized (not declared with an initializer and no assignment to it has been performed prior to use), the behavior is undefined."

But on the following C code compiled with Clang 22.1.6 and `-fsanitize=undefined` under Debian/unstable, I do not get any warning.

```c
int main(void)
{
int x;
return x;
}
```

Note that this should not be confused with "MemorySanitizer: use-of-uninitialized-value" obtained by using `-fsanitize=memory`, because the following code also triggers a MemorySanitizer warning while this is not undefined behavior (the condition "never had its address taken" is not satisfied).

```c
int main(void)
{
int x;
(void) &x;
return x;
}
```

Said otherwise, one cannot distinguish these two cases while there is a difference for ISO C23.

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.