[clang] 5d64b37 - [clang][Interp] Convert blocks to DeadBlocks when destroying frames (#101794)

via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 2 23:04:28 PDT 2024


Author: Timm Baeder
Date: 2024-08-03T08:04:24+02:00
New Revision: 5d64b37f3403dc1683bd4f8166f4286e6562c6cf

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

LOG: [clang][Interp] Convert blocks to DeadBlocks when destroying frames (#101794)

This doesn't fix the attached test case, but at least we're not crashing
anymore.

Added: 
    

Modified: 
    clang/lib/AST/Interp/InterpFrame.cpp
    clang/test/AST/Interp/new-delete.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp b/clang/lib/AST/Interp/InterpFrame.cpp
index 1c37450ae1c6e..9e7bf9972a578 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -75,9 +75,7 @@ InterpFrame::~InterpFrame() {
   if (Func) {
     for (auto &Scope : Func->scopes()) {
       for (auto &Local : Scope.locals()) {
-        Block *B = localBlock(Local.Offset);
-        if (B->isInitialized())
-          B->invokeDtor();
+        S.deallocate(localBlock(Local.Offset));
       }
     }
   }

diff  --git a/clang/test/AST/Interp/new-delete.cpp b/clang/test/AST/Interp/new-delete.cpp
index ae76950f13731..ddf91005c61d9 100644
--- a/clang/test/AST/Interp/new-delete.cpp
+++ b/clang/test/AST/Interp/new-delete.cpp
@@ -564,6 +564,27 @@ namespace DeleteThis {
                                                // both-note {{in call to 'super_secret_double_delete()'}}
 }
 
+/// FIXME: This is currently diagnosed, but should work.
+/// If the destructor for S is _not_ virtual however, it should fail.
+namespace CastedDelete {
+  struct S {
+    constexpr S(int *p) : p(p) {}
+    constexpr virtual ~S() { *p = 1; }
+    int *p;
+  };
+  struct T: S {
+    // implicit destructor defined eagerly because it is constexpr and virtual
+    using S::S;
+  };
+
+  constexpr int vdtor_1() {
+    int a;
+    delete (S*)new T(&a); // expected-note {{delete of pointer to subobject}}
+    return a;
+  }
+  static_assert(vdtor_1() == 1); // expected-error {{not an integral constant expression}} \
+                                 // expected-note {{in call to}}
+}
 
 #else
 /// Make sure we reject this prior to C++20


        


More information about the cfe-commits mailing list