Issue 64296
Summary `__builtin_ctz` does not work at compile time if the argument is 0
Labels good first issue, clang:frontend, consteval
Assignees
Reporter tbaederr
    
```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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to