[clang] e6ec366 - [clang][Interp] Fix classifying __builtin_addressof() argument
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 24 10:27:38 PDT 2024
Author: Timm Bäder
Date: 2024-06-24T19:27:28+02:00
New Revision: e6ec3664cb72fd95669cb516b21572da4236fd91
URL: https://github.com/llvm/llvm-project/commit/e6ec3664cb72fd95669cb516b21572da4236fd91
DIFF: https://github.com/llvm/llvm-project/commit/e6ec3664cb72fd95669cb516b21572da4236fd91.diff
LOG: [clang][Interp] Fix classifying __builtin_addressof() argument
It's an lvalue, so we need to use the classify() taking an expression.
Added:
Modified:
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index aeb6ec42eb39e..98928b3c22d7c 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -609,8 +609,8 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
- PrimType PtrT =
- S.getContext().classify(Call->getArg(0)->getType()).value_or(PT_Ptr);
+ assert(Call->getArg(0)->isLValue());
+ PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
if (PtrT == PT_FnPtr) {
const FunctionPointer &Arg = S.Stk.peek<FunctionPointer>();
diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 10c62a43ef33b..f43be1d3c0403 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -473,6 +473,10 @@ namespace AddressOf {
constexpr _Complex float F = {3, 4};
static_assert(__builtin_addressof(F) == &F, "");
+
+ void testAddressof(int x) {
+ static_assert(&x == __builtin_addressof(x), "");
+ }
}
namespace std {
More information about the cfe-commits
mailing list