Skip to content

Commit e6ec366

Browse files
committed
[clang][Interp] Fix classifying __builtin_addressof() argument
It's an lvalue, so we need to use the classify() taking an expression.
1 parent 5d15f60 commit e6ec366

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
609609
const InterpFrame *Frame,
610610
const Function *Func,
611611
const CallExpr *Call) {
612-
PrimType PtrT =
613-
S.getContext().classify(Call->getArg(0)->getType()).value_or(PT_Ptr);
612+
assert(Call->getArg(0)->isLValue());
613+
PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
614614

615615
if (PtrT == PT_FnPtr) {
616616
const FunctionPointer &Arg = S.Stk.peek<FunctionPointer>();

clang/test/AST/Interp/functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ namespace AddressOf {
473473

474474
constexpr _Complex float F = {3, 4};
475475
static_assert(__builtin_addressof(F) == &F, "");
476+
477+
void testAddressof(int x) {
478+
static_assert(&x == __builtin_addressof(x), "");
479+
}
476480
}
477481

478482
namespace std {

0 commit comments

Comments
 (0)