llvm / llvm/llvm-project

[analyzer] Model initialization of const global variables without initialization expression in C

Open
#200,050 6 comments 0 reactions 0 assignees View on GitHub
clang:static analyzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

As @earnol discovered during discussing #199271, the following C code is not modelled properly by ClangSA.

```c
const int a[4] = {};
const int b[4];

int test() {
clang_analyzer_eval(a[0] == 0) // TRUE
clang_analyzer_eval(b[0] == 0) // should be TRUE, but currently is UNKNOWN
return 0;
}
```

In C, it is valid to have a const global variable without an initializer expression, and according to the language spec, it should be initialized to 0.

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.