https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/219994

They have the same lifetime as `Program`, so use the allocator we're already 
carrying around.

>From 1b08e01838a9498a9f9ff7f502f11e6f089ea998 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 31 Aug 2026 16:38:35 +0200
Subject: [PATCH] asdf

---
 clang/lib/AST/ByteCode/Program.cpp |  4 ++--
 clang/lib/AST/ByteCode/Program.h   | 12 ++++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

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

Reply via email to