https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/196600

Raw pointer return from `FunctionInfo::create` caused leaks in callers
like `computeABIInfoUsingLib`, breaking BPF tests on ASan bots.
Using `std::unique_ptr` enforces automatic cleanup.

Fixes leak from 07b5dfe9473c.
Buildbot: https://lab.llvm.org/buildbot/#/builders/52/builds/17090

TAG=agy
CONV=08a959c8-59e8-47cc-a0e2-f39f7aee1c9d


>From d678d16ddb20cc43b14d72aa919e51f6b6027428 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <[email protected]>
Date: Fri, 8 May 2026 11:22:15 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.7
---
 clang/lib/CodeGen/CGCall.cpp         |  2 +-
 llvm/include/llvm/ABI/FunctionInfo.h |  2 +-
 llvm/lib/ABI/FunctionInfo.cpp        | 11 ++++++-----
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 1cafe364c4c42..a2b9c945788ee 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -843,7 +843,7 @@ void CodeGenModule::computeABIInfoUsingLib(CGFunctionInfo 
&FI) {
   if (Required.allowsOptionalArgs())
     NumRequired = Required.getNumRequiredArgs();
 
-  llvm::abi::FunctionInfo *AbiFI = llvm::abi::FunctionInfo::create(
+  auto AbiFI = llvm::abi::FunctionInfo::create(
       FI.getCallingConvention(), AbiMapper->convertType(FI.getReturnType()),
       MappedArgTypes, NumRequired);
 
diff --git a/llvm/include/llvm/ABI/FunctionInfo.h 
b/llvm/include/llvm/ABI/FunctionInfo.h
index 7f7b6a44ba6ad..0ebd0700836e2 100644
--- a/llvm/include/llvm/ABI/FunctionInfo.h
+++ b/llvm/include/llvm/ABI/FunctionInfo.h
@@ -234,7 +234,7 @@ class FunctionInfo final : private 
TrailingObjects<FunctionInfo, ArgEntry> {
 
   unsigned arg_size() const { return NumArgs; }
 
-  static FunctionInfo *
+  static std::unique_ptr<FunctionInfo>
   create(CallingConv::ID CC, const Type *ReturnType,
          ArrayRef<const Type *> ArgTypes,
          std::optional<unsigned> NumRequired = std::nullopt);
diff --git a/llvm/lib/ABI/FunctionInfo.cpp b/llvm/lib/ABI/FunctionInfo.cpp
index f89d90c74ea03..7096392135ce8 100644
--- a/llvm/lib/ABI/FunctionInfo.cpp
+++ b/llvm/lib/ABI/FunctionInfo.cpp
@@ -12,16 +12,17 @@
 using namespace llvm;
 using namespace llvm::abi;
 
-FunctionInfo *FunctionInfo::create(CallingConv::ID CC, const Type *ReturnType,
-                                   ArrayRef<const Type *> ArgTypes,
-                                   std::optional<unsigned> NumRequired) {
+std::unique_ptr<FunctionInfo>
+FunctionInfo::create(CallingConv::ID CC, const Type *ReturnType,
+                     ArrayRef<const Type *> ArgTypes,
+                     std::optional<unsigned> NumRequired) {
 
   assert(!NumRequired || *NumRequired <= ArgTypes.size());
 
   void *Buffer = operator new(totalSizeToAlloc<ArgEntry>(ArgTypes.size()));
 
-  FunctionInfo *FI =
-      new (Buffer) FunctionInfo(CC, ReturnType, ArgTypes.size(), NumRequired);
+  std::unique_ptr<FunctionInfo> FI(
+      new (Buffer) FunctionInfo(CC, ReturnType, ArgTypes.size(), NumRequired));
 
   ArgEntry *Args = FI->getTrailingObjects();
   for (unsigned I = 0; I < ArgTypes.size(); ++I)

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to