Issue |
130649
|
Summary |
`__builtin_constant_p` incorrect with undefined variables
|
Labels |
new issue
|
Assignees |
|
Reporter |
kees
|
Given this situation:
```c
// -O2 -Wall
extern void knowable(void);
extern void unknowable(void);
void test(void)
{
char buf[8];
// The end of "buf" is undefined. That shouldn't make
// __builtin_constant_p() undefined nor true, though.
// It should just be false.
if (__builtin_constant_p(buf[sizeof(buf)-1])) {
knowable();
} else {
unknowable();
}
}
```
Clang is incorrectly resolving `__builtin_constant_p()` to `true` (or `undefined`) instead of `false`. GCC correctly resolves it to `false` (and emits a warning about using `buf` uninitialized).
Isolated from ClangBuiltLinux: https://github.com/ClangBuiltLinux/linux/issues/2073
Providing an initializer to `buf` makes this go away (in the sane that now it is correctly "knowable"). GCC flips over to `knowable()`:
```
char buf[8] = "";
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs