<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/130649>130649</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `__builtin_constant_p` incorrect with undefined variables
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kees
      </td>
    </tr>
</table>

<pre>
    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] = "";
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8VE1v4zgM_TXyhWgg07FjH3xIG2QwwAK7hwH2WMg2HXOqSIU-kun8-oUct0mz2w0MGAqfyfceSSnv-WCIWlE-inKXqRgm69oXIp91dnhrv_GJDISJPXgOUQW2RhRbIeenkpenTwfcC9zDw58ID38rrYXc0q9AzsDJ8gAvxp5Vp0lgnc4CG1E83mGi-Qol5HZGBPLhJia3YpPCAAD9pBx0cRTlYy3K3cd3KbZw-zERkBnAjiAQExYR2EM0A41saFjBj0kF8JONejACNwGO6oU-Z3l-7iLrwOa5t8YHZcLzq8BaYHNNBMY6CC6SwCcIk42HafU5y_f3MvAz-gAdwai0p3cUJ4r1F6UuKj3_JjsuR2we8qQam8Tj6kr63Zj6YejMZLMD0p5u4EI2n5pwj58d3922_mLyk1bmkKxk01vnqA_6DRx5q09sDiAq-bVropIQbMLMhlUyKbcu_fHhZyqEDbDxgdSlgZWcDROVXMG3pye4r0seOCyJ35EpszID0JGDBwVn5UzipzobA0S_cE2GVhKiYcOBlebflMZtddH63VutAg0wOnuEWfljkvYHm_hLFFuYQnj1aUnmTh84TLFb9fYocH-Pxr1e3ux9JC9wj3JTXAr95eyJh5mfgSsVt4haWKYB9ZcNPVhQZ_WWVHJaWgKvDEFIM23sOfnB_sYogXjtNSaFs5Oj5lcP9vRR6W4gKvnvG-C_lxBEsYM5NS77-I7PhrYYmqJRGbX5Zp1X2Gw2dTa1m6FZq3Gs6xHrjtZNMfSyKxpsyn4YsewzblFiKYtc5rXEslqtZZPnVd7R2FRVX6zFWtJRsV5pfTqurDtks7dtXshq3WRadaT9fOEhGjrDHE0My13m2vTRQxcPXqylZh_8NU3goKn9apYreR1-OHOYbm6Dk3KcDPRZdLr9n_lItZbXw6uzP6kPt7OxSDi1-E8AAAD__-Pcwjo">