Skip to content

Commit 27d730b

Browse files
authored
[clang][bytecode] Create InterpState allocator on demand (#158802)
We often don't need it (especially in C), so make this optional and create it only when we first allocate something.
1 parent dd29fbd commit 27d730b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

clang/lib/AST/ByteCode/InterpState.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ class InterpState final : public State, public SourceMapper {
122122
StdAllocatorCaller getStdAllocatorCaller(StringRef Name) const;
123123

124124
void *allocate(size_t Size, unsigned Align = 8) const {
125-
return Allocator.Allocate(Size, Align);
125+
if (!Allocator)
126+
Allocator.emplace();
127+
return Allocator->Allocate(Size, Align);
126128
}
127129
template <typename T> T *allocate(size_t Num = 1) const {
128130
return static_cast<T *>(allocate(Num * sizeof(T), alignof(T)));
@@ -188,7 +190,7 @@ class InterpState final : public State, public SourceMapper {
188190
/// for.
189191
llvm::SmallVector<const Block *> InitializingBlocks;
190192

191-
mutable llvm::BumpPtrAllocator Allocator;
193+
mutable std::optional<llvm::BumpPtrAllocator> Allocator;
192194
};
193195

194196
class InterpStateCCOverride final {

0 commit comments

Comments
 (0)