[clang] [clang][bytecode] Use InterpState's allocator in DynamicAllocator (PR #224893)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 20 01:23:34 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
This saves us yet another BumpPtrAllocator.
---
Full diff: https://github.com/llvm/llvm-project/pull/224893.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/DynamicAllocator.h (+3-3)
- (modified) clang/lib/AST/ByteCode/InterpState.h (+5-3)
``````````diff
diff --git a/clang/lib/AST/ByteCode/DynamicAllocator.h b/clang/lib/AST/ByteCode/DynamicAllocator.h
index 2336c3f3316c31..cc6a315083b614 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 920197d8021c06..91d0c5be2bb0c5 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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/224893
More information about the cfe-commits
mailing list