[clang] 4881cbd - [clang][Interp] Fix MemberExpr initializing an existing value (#79973)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 07:41:59 PST 2024


Author: Timm Baeder
Date: 2024-02-05T16:41:55+01:00
New Revision: 4881cbd407e73f940a8e9ede501c2eee190ec9dd

URL: https://github.com/llvm/llvm-project/commit/4881cbd407e73f940a8e9ede501c2eee190ec9dd
DIFF: https://github.com/llvm/llvm-project/commit/4881cbd407e73f940a8e9ede501c2eee190ec9dd.diff

LOG: [clang][Interp] Fix MemberExpr initializing an existing value (#79973)

This is similar to c1ad363e6eba308fa94c47374ee98b3c79693a35, but with
the additional twist that initializing an existing value from a
`MemberExpr` was not working correctly.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/cxx98.cpp
    clang/test/SemaCXX/pr72025.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index cefcebe18c6b6..24fa3d16896e8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1129,7 +1129,7 @@ bool ByteCodeExprGen<Emitter>::VisitMemberExpr(const MemberExpr *E) {
   if (DiscardResult)
     return this->discard(Base);
 
-  if (!this->visit(Base))
+  if (!this->delegate(Base))
     return false;
 
   // Base above gives us a pointer on the stack.
@@ -1617,8 +1617,10 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
       return this->emitGetPtrLocal(*LocalIndex, E);
     }
   } else {
+    const Expr *Inner = E->getSubExpr()->skipRValueSubobjectAdjustments();
+
     if (std::optional<unsigned> LocalIndex =
-            allocateLocal(SubExpr, /*IsExtended=*/true)) {
+            allocateLocal(Inner, /*IsExtended=*/true)) {
       if (!this->emitGetPtrLocal(*LocalIndex, E))
         return false;
       return this->visitInitializer(SubExpr);

diff  --git a/clang/test/AST/Interp/cxx98.cpp b/clang/test/AST/Interp/cxx98.cpp
index 79f93c8d78f16..1acc74a8290a0 100644
--- a/clang/test/AST/Interp/cxx98.cpp
+++ b/clang/test/AST/Interp/cxx98.cpp
@@ -30,3 +30,11 @@ int NCI; // both-note {{declared here}}
 int NCIA[NCI]; // both-warning {{variable length array}} \
                // both-error {{variable length array}} \\
                // both-note {{read of non-const variable 'NCI'}}
+
+
+struct V {
+  char c[1];
+  banana V() : c("i") {} // both-error {{unknown type name 'banana'}} \
+                         // both-error {{constructor cannot have a return type}}
+};
+_Static_assert(V().c[0], ""); // both-error {{is not an integral constant expression}}

diff  --git a/clang/test/SemaCXX/pr72025.cpp b/clang/test/SemaCXX/pr72025.cpp
index 9f0a4b0f43630..ac55f27728a36 100644
--- a/clang/test/SemaCXX/pr72025.cpp
+++ b/clang/test/SemaCXX/pr72025.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only %s
+// RUN: %clang_cc1 -verify -std=c++03 -fsyntax-only -fexperimental-new-constant-interpreter %s
 struct V {
   char c[2];
   banana V() : c("i") {} // expected-error {{unknown type name}}


        


More information about the cfe-commits mailing list