[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 16 10:01:23 PDT 2022


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As discussed with @aaron.ballman on IRC.

This reverts https://reviews.llvm.org/rGa8843643cd75d0e93ebcf3f30b470d2b8e59868d

I have ASan enabled locally and with this patch, the test suite now works fine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134054

Files:
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/references.cpp


Index: clang/test/AST/Interp/references.cpp
===================================================================
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@
 constexpr const int &MCE = 1; // expected-error{{must be initialized by a constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
Index: clang/lib/AST/Interp/Program.h
===================================================================
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@
 public:
   Program(Context &Ctx) : Ctx(Ctx) {}
 
+  ~Program() {
+    // Records might actually allocate memory themselves, but they
+    // are allocated using a BumpPtrAllocator. Call their desctructors
+    // here manually so they are properly freeing their resources.
+    for (auto It : Records)
+      It.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134054.460813.patch
Type: text/x-patch
Size: 1230 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/ad0316b9/attachment.bin>


More information about the cfe-commits mailing list