https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/220922
They have the same lifetime, so might as well use the existing allocator. >From cece1886f58aaa640eebc062486b431e1c864a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Thu, 3 Sep 2026 07:53:06 +0200 Subject: [PATCH] locals --- clang/lib/AST/ByteCode/EvalEmitter.cpp | 20 ++++++-------------- clang/lib/AST/ByteCode/EvalEmitter.h | 6 ++---- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp index 80eb593c2f6c4..93b332cda6e19 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.cpp +++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp @@ -21,14 +21,6 @@ EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk) : Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {} -EvalEmitter::~EvalEmitter() { - for (auto &V : Locals) { - Block *B = reinterpret_cast<Block *>(V.get()); - if (B->isInitialized()) - B->invokeDtor(); - } -} - /// Clean up all our resources. This needs to done in failed evaluations before /// we call InterpStack::clear(), because there might be a Pointer on the stack /// pointing into a Block in the EvalEmitter. @@ -151,11 +143,11 @@ EvalEmitter::LabelTy EvalEmitter::getLabel() { return NextLabel++; } Scope::Local EvalEmitter::createLocal(const Descriptor *D) { // Allocate memory for a local. - auto Memory = std::make_unique<char[]>(sizeof(Block) + D->getAllocSize() + - Block::InlineDescMD); - auto *B = new (Memory.get()) Block(Ctx.getEvalID(), D, Block::InlineDescMD, - /*IsStatic=*/false); - B->invokeCtorNoMemset(); + char *Memory = reinterpret_cast<char *>( + S.allocate(sizeof(Block) + D->getAllocSize() + Block::InlineDescMD)); + auto *B = new (Memory) Block(Ctx.getEvalID(), D, Block::InlineDescMD, + /*IsStatic=*/false); + B->invokeCtor(); // Initialize local variable inline descriptor. auto &Desc = B->getBlockDesc<InlineDescriptor>(); @@ -169,7 +161,7 @@ Scope::Local EvalEmitter::createLocal(const Descriptor *D) { // Register the local. unsigned Off = Locals.size(); - Locals.push_back(std::move(Memory)); + Locals.push_back(Memory); return {D, Off}; } diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h b/clang/lib/AST/ByteCode/EvalEmitter.h index a80b573a7df8b..4f02f796097aa 100644 --- a/clang/lib/AST/ByteCode/EvalEmitter.h +++ b/clang/lib/AST/ByteCode/EvalEmitter.h @@ -63,8 +63,6 @@ class EvalEmitter : public SourceMapper { protected: EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk); - virtual ~EvalEmitter(); - /// Define a label. void emitLabel(LabelTy Label); /// Create a label. @@ -126,11 +124,11 @@ class EvalEmitter : public SourceMapper { std::optional<PtrCallback> PtrCB; /// Temporaries which require storage. - llvm::SmallVector<std::unique_ptr<char[]>> Locals; + llvm::SmallVector<char *> Locals; Block *getLocal(unsigned Index) const { assert(Index < Locals.size()); - return reinterpret_cast<Block *>(Locals[Index].get()); + return reinterpret_cast<Block *>(Locals[Index]); } void updateGlobalTemporaries(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
