Author: Timm Baeder
Date: 2026-09-20T12:16:55+02:00
New Revision: 2ef90337355eee4384d4ac61bf038175a24583ab

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

LOG: [clang][bytecode] Use InterpState's allocator in DynamicAllocator (#224893)

This saves us yet another BumpPtrAllocator.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/DynamicAllocator.h
    clang/lib/AST/ByteCode/InterpState.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/DynamicAllocator.h 
b/clang/lib/AST/ByteCode/DynamicAllocator.h
index 2336c3f3316c3..cc6a315083b61 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.h
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.h
@@ -62,7 +62,8 @@ class DynamicAllocator final {
   };
 
 public:
-  DynamicAllocator() = default;
+  DynamicAllocator(llvm::BumpPtrAllocator &DescAlloc)
+      : DescAllocator(DescAlloc) {}
   DynamicAllocator(DynamicAllocator &) = delete;
   DynamicAllocator(DynamicAllocator &&) = delete;
   ~DynamicAllocator();
@@ -105,8 +106,7 @@ class DynamicAllocator final {
   // to them.
   llvm::SmallVector<Allocation> DeadAllocations;
 
-  using PoolAllocTy = llvm::BumpPtrAllocator;
-  PoolAllocTy DescAllocator;
+  llvm::BumpPtrAllocator &DescAllocator;
 
   /// Allocates a new descriptor.
   template <typename... Ts> Descriptor *allocateDescriptor(Ts &&...Args) {

diff  --git a/clang/lib/AST/ByteCode/InterpState.h 
b/clang/lib/AST/ByteCode/InterpState.h
index 920197d8021c0..91d0c5be2bb0c 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -80,7 +80,9 @@ class InterpState final : public State {
 
   DynamicAllocator &getAllocator() {
     if (!Alloc) {
-      Alloc = std::make_unique<DynamicAllocator>();
+      if (!Allocator)
+        Allocator.emplace();
+      Alloc = std::make_unique<DynamicAllocator>(*Allocator);
     }
 
     return *Alloc;
@@ -223,10 +225,10 @@ class InterpState final : public State {
   DeadBlock *DeadBlocks = nullptr;
   /// Reference to the offset-source mapping.
   SourceMapper *M;
-  /// Allocator used for dynamic allocations performed via the program.
-  std::unique_ptr<DynamicAllocator> Alloc;
   /// Allocator for everything else, e.g. floating-point values.
   mutable std::optional<llvm::BumpPtrAllocator> Allocator;
+  /// Allocator used for dynamic allocations performed via the program.
+  std::unique_ptr<DynamicAllocator> Alloc;
   /// Diagnose that we've reached the constexpr step limit.
   bool diagnoseStepLimitExceeded(CodePtr OpPC);
 


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to