[clang] 4cf607f - [clang][Interp] Fix visiting non-FieldDecl MemberExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 11 09:13:36 PDT 2024


Author: Timm Bäder
Date: 2024-06-11T18:13:28+02:00
New Revision: 4cf607fa15fd9ccd79115095a1eb02e0cd83e1a9

URL: https://github.com/llvm/llvm-project/commit/4cf607fa15fd9ccd79115095a1eb02e0cd83e1a9
DIFF: https://github.com/llvm/llvm-project/commit/4cf607fa15fd9ccd79115095a1eb02e0cd83e1a9.diff

LOG: [clang][Interp] Fix visiting non-FieldDecl MemberExprs

Ignore the base and visit the Member decl like a regular DeclRefExpr.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/SemaCXX/ms-const-member-expr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0385ca4b3a063..820e4cc44a7bc 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1494,6 +1494,9 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
     return false;
   }
 
+  if (!isa<FieldDecl>(Member))
+    return this->discard(Base) && this->visitDeclRef(Member, E);
+
   if (Initializing) {
     if (!this->delegate(Base))
       return false;
@@ -1503,19 +1506,16 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
   }
 
   // Base above gives us a pointer on the stack.
-  if (const auto *FD = dyn_cast<FieldDecl>(Member)) {
-    const RecordDecl *RD = FD->getParent();
-    const Record *R = getRecord(RD);
-    if (!R)
-      return false;
-    const Record::Field *F = R->getField(FD);
-    // Leave a pointer to the field on the stack.
-    if (F->Decl->getType()->isReferenceType())
-      return this->emitGetFieldPop(PT_Ptr, F->Offset, E) && maybeLoadValue();
-    return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
-  }
-
-  return false;
+  const auto *FD = cast<FieldDecl>(Member);
+  const RecordDecl *RD = FD->getParent();
+  const Record *R = getRecord(RD);
+  if (!R)
+    return false;
+  const Record::Field *F = R->getField(FD);
+  // Leave a pointer to the field on the stack.
+  if (F->Decl->getType()->isReferenceType())
+    return this->emitGetFieldPop(PT_Ptr, F->Offset, E) && maybeLoadValue();
+  return this->emitGetPtrFieldPop(F->Offset, E) && maybeLoadValue();
 }
 
 template <class Emitter>

diff  --git a/clang/test/SemaCXX/ms-const-member-expr.cpp b/clang/test/SemaCXX/ms-const-member-expr.cpp
index 72cfe76fbe43a..8312f84b550f0 100644
--- a/clang/test/SemaCXX/ms-const-member-expr.cpp
+++ b/clang/test/SemaCXX/ms-const-member-expr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify
+// RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify -fexperimental-new-constant-interpreter
 
 struct S {
   enum { E = 1 };


        


More information about the cfe-commits mailing list