[clang] 84f1df8 - [clang][Interp] Properly destruct allocated Records

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 29 03:51:40 PDT 2022


Author: Timm Bäder
Date: 2022-09-29T12:50:56+02:00
New Revision: 84f1df8aacd0c3eb72f20f91c9af227b65d4c7da

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

LOG: [clang][Interp] Properly destruct allocated Records

We are otherwise leaking some memory the records might allocate
themselves.

Differential Revision: https://reviews.llvm.org/D134054

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Program.h b/clang/lib/AST/Interp/Program.h
index 4807b752deed7..6a00246644172 100644
--- a/clang/lib/AST/Interp/Program.h
+++ b/clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@ class Program final {
 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 RecordPair : Records)
+      RecordPair.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 

diff  --git a/clang/test/AST/Interp/references.cpp b/clang/test/AST/Interp/references.cpp
index 2b5187ca29dd9..9a23c0a92e530 100644
--- a/clang/test/AST/Interp/references.cpp
+++ b/clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@ static_assert(testGetValue() == 30, "");
 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 @@ constexpr int RefToMemberExpr() {
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}


        


More information about the cfe-commits mailing list