[clang] [clang][bytecode] Yet another __builtin_constant_p implementation (PR #130143)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 7 02:29:23 PST 2025


tbaederr wrote:

For this case:
```c++
constexpr bool test(int& i) {
  return __builtin_constant_p(i = 5);
}
constexpr int f() {
  int a = 10;
  test(a);
  return a;
}
static_assert(f() == 5);
```
I simply don't. This also works in GCC.

For
```c++
bool test(int& i) {
  return __builtin_constant_p(i = 5);
}
```
both interpreters produce
```llvm
define dso_local noundef zeroext i1 @_Z4testRi(ptr noundef nonnull align 4 dereferenceable(4) %i) #0 {
entry:
  %i.addr = alloca ptr, align 8
  store ptr %i, ptr %i.addr, align 8
  ret i1 false
}
```
in the bytecode case, the bcp call returns false because the bcp call is evaluated standalone, without the parameters being registered at all. That means the `DeclRefExpr` to it will be a dummy pointer and modifying those always fails.

https://github.com/llvm/llvm-project/pull/130143


More information about the cfe-commits mailing list