[clang] e98abc3 - [clang][Interp] Emit dtors when ignoring CXXConstructExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 00:49:11 PST 2024


Author: Timm Bäder
Date: 2024-02-19T09:48:50+01:00
New Revision: e98abc3ea0796a5d78eb48f2ee9b3019e8133562

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

LOG: [clang][Interp] Emit dtors when ignoring CXXConstructExprs

The comment says we should emit destructors, but we didn't.

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 e8b0fffd5ee34d..a778c300fc33a0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1848,6 +1848,8 @@ bool ByteCodeExprGen<Emitter>::VisitCXXConstructExpr(
 
     // Immediately call the destructor if we have to.
     if (DiscardResult) {
+      if (!this->emitRecordDestruction(getRecord(E->getType())))
+        return false;
       if (!this->emitPopPtr(E))
         return false;
     }

diff  --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index 62f1f1d6e426c3..7cc5987e0a958f 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -335,9 +335,9 @@ namespace InitializerTemporaries {
   };
 
   constexpr int f() {
-    S{}; // ref-note {{in call to 'S{}.~S()'}}
-    /// FIXME: Wrong source location below.
-    return 12; // expected-note {{in call to '&S{}->~S()'}}
+    S{}; // ref-note {{in call to 'S{}.~S()'}} \
+         // expected-note {{in call to '&S{}->~S()'}}
+    return 12;
   }
   static_assert(f() == 12); // both-error {{not an integral constant expression}} \
                             // both-note {{in call to 'f()'}}
@@ -604,9 +604,9 @@ namespace Destructors {
     }
   };
   constexpr int testS() {
-    S{}; // ref-note {{in call to 'S{}.~S()'}}
-    return 1; // expected-note {{in call to '&S{}->~S()'}}
-              // FIXME: ^ Wrong line
+    S{}; // ref-note {{in call to 'S{}.~S()'}} \
+         // expected-note {{in call to '&S{}->~S()'}}
+    return 1;
   }
   static_assert(testS() == 1); // both-error {{not an integral constant expression}} \
                                // both-note {{in call to 'testS()'}}


        


More information about the cfe-commits mailing list