[clang] c09384e - [clang][Interp] Support MemberExprs pointing to VarDecls
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 16 03:34:47 PDT 2024
Author: Timm Bäder
Date: 2024-04-16T12:34:35+02:00
New Revision: c09384e2b419c7b4e4167e0d0295d9018cc6169c
URL: https://github.com/llvm/llvm-project/commit/c09384e2b419c7b4e4167e0d0295d9018cc6169c
DIFF: https://github.com/llvm/llvm-project/commit/c09384e2b419c7b4e4167e0d0295d9018cc6169c.diff
LOG: [clang][Interp] Support MemberExprs pointing to VarDecls
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 4a7b40440770e3..a069f3ec27e721 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1267,10 +1267,19 @@ template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
// 'Base.Member'
const Expr *Base = E->getBase();
+ const ValueDecl *Member = E->getMemberDecl();
if (DiscardResult)
return this->discard(Base);
+ if (const auto *VD = dyn_cast<VarDecl>(Member)) {
+ // I am almost confident in saying that a var decl must be static
+ // and therefore registered as a global variable. But this will probably
+ // turn out to be wrong some time in the future, as always.
+ if (auto GlobalIndex = P.getGlobal(VD))
+ return this->emitGetPtrGlobal(*GlobalIndex, E);
+ }
+
if (Initializing) {
if (!this->delegate(Base))
return false;
@@ -1280,8 +1289,6 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
}
// Base above gives us a pointer on the stack.
- // TODO: Implement non-FieldDecl members.
- const ValueDecl *Member = E->getMemberDecl();
if (const auto *FD = dyn_cast<FieldDecl>(Member)) {
const RecordDecl *RD = FD->getParent();
const Record *R = getRecord(RD);
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index f251497ed70182..2c33fa1bf88432 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1309,3 +1309,11 @@ namespace pr18633 {
func2<int>();
}
}
+
+namespace {
+ struct F {
+ static constexpr int Z = 12;
+ };
+ F f;
+ static_assert(f.Z == 12, "");
+}
More information about the cfe-commits
mailing list