llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-codegen Author: Vitaly Buka (vitalybuka) <details> <summary>Changes</summary> 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 --- Full diff: https://github.com/llvm/llvm-project/pull/196600.diff 3 Files Affected: - (modified) clang/lib/CodeGen/CGCall.cpp (+1-1) - (modified) llvm/include/llvm/ABI/FunctionInfo.h (+1-1) - (modified) llvm/lib/ABI/FunctionInfo.cpp (+6-5) ``````````diff 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) `````````` </details> https://github.com/llvm/llvm-project/pull/196600 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
