You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang] Consider reachability for file-scope warnings on initializers
Suppress runtime warnings for unreachable code in global variable
initializers while maintaining warnings for the same code in functions.
For context, some global variable declarations using ternaries can emit
warnings during initialization even when a particular expression is
never used. This behavior differs from GCC since they properly emit
warnings based on reachability -- even at file scope.
The simplest example is:
```c
$ cat test.c
unsigned long long b1 = 1 ? 0 : 1ULL << 64;
$ clang-21 -fsyntax-only test.c
test.c:1:39: warning: shift count >= width of type [-Wshift-count-overflow]
1 | unsigned long long foo = 1 ? 0 : 1ULL << 64;
| ^ ~~
$ gcc-13 -fsyntax-only test.c
<empty>
```
Clang previously emitted a ``-Wshift-count-overflow`` warning regardless
of branch taken. This PR constructs a CFG and defers runtime diagnostic
emission until we can analyze the CFG for reachability.
To be clear, the intention is only to modify initializers in global
scope and only remove warnings if unreachable, no new warnings should
pop up anywhere.
Link: https://reviews.llvm.org/D63889 (original PR by Nathan Huckleberry)
Link: ClangBuiltLinux/linux#92
Co-Authored-By: Nathan Huckleberry <[email protected]>
Signed-off-by: Justin Stitt <[email protected]>
0 commit comments