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

    <tr>
        <th>Summary</th>
        <td>
            `__builtin_ctz` does not work at compile time if the argument is 0
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            good first issue,
            clang:frontend,
            consteval
      </td>
    </tr>

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

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

<pre>
    
```c++
constexpr int a = __builtin_ctz(0);
```

Clang refuses to [compile this](https://godbolt.org/z/nqM4sKvKb):

```console
<source>:3:19: error: constexpr variable 'a' must be initialized by a constant expression
    3 | constexpr int a = __builtin_ctz(0);
      | ^~~~~~~~~~~~~~~~
```

Both GCC and ICC compile this just fine and I don't see a reason why the argument should be rejected if it's 0?

`APInt::countr_zero` even states in its documentation:
```
Returns
    BitWidth if the value is zero, otherwise returns the number of zeros from the least significant bit to the first one bit. 
```

so returns what I would expect for 0.

This should be easy to fix, just remove the extra `if (!Val)` check in `ExprConstant.cpp` and adjust (or add) test cases.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVM2O4zYMfhrmQmygSIljH3xIMpNisChQFEV7HMgWHWvXllKRzvwc-uyFnHSzO4cFKgiJJZL6yI8_ltmfAlENmz1sHhZ2kj6mWhpLjlJaNNG91aAeQO2gUNfdgt7nPd-2MbDQ6zmhD4IWwTzg83Mz-UF8eG7lHXSpQFdg9h-euR3n38NgwwkTdRMTo0SEzb6N49kPhNJ7hs0D6LIXOTOYHegj6OMpuiYOsozpBPr4DvoY_v51zZ8vn5sZb_c9wN35GDgOdLs1B45TagnMI5idAbNbZUuklGLKH_fwLjZ52wyEoLcW9BbHiQUbQh-8eDv4d3LYvKG92tggmO2I2cdwhUNENAjbA_5v1nBe2RQ2j__8uH7C6z5Kj78cDmiDw6dDBr6Til9yBJ0PdBWjiw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