llvm-project/clang/test/CodeGen/bitcast-based-lvalue.c
Tommy Chiang d4efbf10f1
[Clang][ExprConst] Handle APValue::LValue in BitCast (#184865)
Instead of marking the branch unreachable, emit an unsupported type
diagnostic and return false when encountering `APValue::LValue` in
`APValueToBufferConverter`.

A good example of this is:
```
long fn() {
  return __builtin_bit_cast(long, (long)&fn);
}
```

Although `&fn` itself is a pointer type, the cast `(long)` converts it
to an integer type, which passes `checkBitCastConstexprEligibilityType`.
Thus, eventually, we see it in Converter, which does not expect an
LValue.

Fixes https://github.com/llvm/llvm-project/issues/44991
2026-03-07 02:06:03 +08:00

8 lines
284 B
C

// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
long fn(void) { return __builtin_bit_cast(long, (long)&fn); }
// CHECK-LABEL: define{{.*}} i64 @fn()
// CHECK: store i64 ptrtoint (ptr @fn to i64), ptr %ref.tmp, align 8
// CHECK: ret i64 %{{.*}}