Author: Timm Baeder Date: 2026-09-01T08:00:59+02:00 New Revision: 813609cdd37fcf5723bd47bd722f47bf4e1f7c07
URL: https://github.com/llvm/llvm-project/commit/813609cdd37fcf5723bd47bd722f47bf4e1f7c07 DIFF: https://github.com/llvm/llvm-project/commit/813609cdd37fcf5723bd47bd722f47bf4e1f7c07.diff LOG: [clang][bytecode] Allocate functions via Program allocator (#219994) They have the same lifetime as `Program`, so use the allocator we're already carrying around. Added: Modified: clang/lib/AST/ByteCode/Program.cpp clang/lib/AST/ByteCode/Program.h Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Program.cpp b/clang/lib/AST/ByteCode/Program.cpp index 257fa9214076e..fdd9d5506160d 100644 --- a/clang/lib/AST/ByteCode/Program.cpp +++ b/clang/lib/AST/ByteCode/Program.cpp @@ -230,10 +230,10 @@ UnsignedOrNone Program::createGlobal(DeclOrExpr D, QualType Ty, bool IsStatic, } Function *Program::getFunction(const FunctionDecl *F) { - F = F->getCanonicalDecl(); + F = F->getFirstDecl(); assert(F); auto It = Funcs.find(F); - return It == Funcs.end() ? nullptr : It->second.get(); + return It == Funcs.end() ? nullptr : It->second; } Record *Program::getOrCreateRecord(const RecordDecl *RD) { diff --git a/clang/lib/AST/ByteCode/Program.h b/clang/lib/AST/ByteCode/Program.h index 19c64f8e914e7..6c9a21728775d 100644 --- a/clang/lib/AST/ByteCode/Program.h +++ b/clang/lib/AST/ByteCode/Program.h @@ -53,6 +53,9 @@ class Program final { if (Record *R = RecordPair.second) R->~Record(); } + + for (Function *F : Funcs.values()) + F->~Function(); } const Context &getContext() const { return Ctx; } @@ -91,9 +94,10 @@ class Program final { /// Creates a new function from a code range. template <typename... Ts> Function *createFunction(const FunctionDecl *Def, Ts &&...Args) { - Def = Def->getCanonicalDecl(); - auto *Func = new Function(Def, std::forward<Ts>(Args)...); - Funcs.insert({Def, std::unique_ptr<Function>(Func)}); + Def = Def->getFirstDecl(); + auto *Func = new (Allocate(sizeof(Function))) + Function(Def, std::forward<Ts>(Args)...); + Funcs.insert({Def, Func}); return Func; } /// Creates an anonymous function. @@ -165,7 +169,7 @@ class Program final { /// Reference to the VM context. Context &Ctx; /// Mapping from decls to cached bytecode functions. - llvm::DenseMap<const FunctionDecl *, std::unique_ptr<Function>> Funcs; + llvm::DenseMap<const FunctionDecl *, Function *> Funcs; /// List of anonymous functions. std::vector<std::unique_ptr<Function>> AnonFuncs; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
