[llvm] 0a3d376 - [llvm][Instrumentor] Fix memory leaks (#196317)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 07:59:17 PDT 2026
Author: Kevin Sala Penades
Date: 2026-05-07T07:59:12-07:00
New Revision: 0a3d376633dadf05b558a24d128378360be78fa6
URL: https://github.com/llvm/llvm-project/commit/0a3d376633dadf05b558a24d128378360be78fa6
DIFF: https://github.com/llvm/llvm-project/commit/0a3d376633dadf05b558a24d128378360be78fa6.diff
LOG: [llvm][Instrumentor] Fix memory leaks (#196317)
Should fix memory leaks introduced in #138958
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Instrumentor.h
llvm/include/llvm/Transforms/IPO/InstrumentorUtils.h
llvm/lib/Transforms/IPO/Instrumentor.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Instrumentor.h b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
index c115bea24bb27..5ddfd3dd4466c 100644
--- a/llvm/include/llvm/Transforms/IPO/Instrumentor.h
+++ b/llvm/include/llvm/Transforms/IPO/Instrumentor.h
@@ -34,6 +34,7 @@
#include <cstdint>
#include <functional>
+#include <memory>
#include <string>
#include <tuple>
@@ -273,17 +274,15 @@ struct BaseConfigurationOption {
/// Create a boolean option with \p Name name, \p Description description and
/// \p DefaultValue as boolean default value.
- static BaseConfigurationOption *createBoolOption(InstrumentationConfig &IC,
- StringRef Name,
- StringRef Description,
- bool DefaultValue);
+ static std::unique_ptr<BaseConfigurationOption>
+ createBoolOption(InstrumentationConfig &IC, StringRef Name,
+ StringRef Description, bool DefaultValue);
/// Create a string option with \p Name name, \p Description description and
/// \p DefaultValue as string default value.
- static BaseConfigurationOption *createStringOption(InstrumentationConfig &IC,
- StringRef Name,
- StringRef Description,
- StringRef DefaultValue);
+ static std::unique_ptr<BaseConfigurationOption>
+ createStringOption(InstrumentationConfig &IC, StringRef Name,
+ StringRef Description, StringRef DefaultValue);
/// Helper union that holds any possible option type.
union ValueTy {
@@ -384,10 +383,10 @@ struct InstrumentationConfig {
SmallVector<BaseConfigurationOption *> BaseConfigurationOptions;
/// The base configuration options.
- BaseConfigurationOption *RuntimePrefix;
- BaseConfigurationOption *TargetRegex;
- BaseConfigurationOption *HostEnabled;
- BaseConfigurationOption *GPUEnabled;
+ std::unique_ptr<BaseConfigurationOption> RuntimePrefix;
+ std::unique_ptr<BaseConfigurationOption> TargetRegex;
+ std::unique_ptr<BaseConfigurationOption> HostEnabled;
+ std::unique_ptr<BaseConfigurationOption> GPUEnabled;
/// The map registered instrumentation opportunities. The map is indexed by
/// the instrumentation location kind and then by the opportunity name. Notice
diff --git a/llvm/include/llvm/Transforms/IPO/InstrumentorUtils.h b/llvm/include/llvm/Transforms/IPO/InstrumentorUtils.h
index 220ec4e61613a..4d7fd55ae825b 100644
--- a/llvm/include/llvm/Transforms/IPO/InstrumentorUtils.h
+++ b/llvm/include/llvm/Transforms/IPO/InstrumentorUtils.h
@@ -48,6 +48,12 @@ struct InstrumentorIRBuilderTy {
I->replaceAllUsesWith(PoisonValue::get(I->getType()));
I->eraseFromParent();
}
+
+ // Delete the alloca lists that may have been allocated.
+ for (auto &KV : AllocaMap) {
+ if (KV.second)
+ delete KV.second;
+ }
}
/// Get a temporary alloca to communicate (large) values with the runtime.
diff --git a/llvm/lib/Transforms/IPO/Instrumentor.cpp b/llvm/lib/Transforms/IPO/Instrumentor.cpp
index cb10a8986a99f..cacf361aca85e 100644
--- a/llvm/lib/Transforms/IPO/Instrumentor.cpp
+++ b/llvm/lib/Transforms/IPO/Instrumentor.cpp
@@ -287,22 +287,26 @@ PreservedAnalyses InstrumentorPass::run(Module &M, ModuleAnalysisManager &MAM) {
return PA;
}
-BaseConfigurationOption *
+std::unique_ptr<BaseConfigurationOption>
BaseConfigurationOption::createBoolOption(InstrumentationConfig &IConf,
StringRef Name, StringRef Description,
bool DefaultValue) {
- auto *BCO = new BaseConfigurationOption(Name, Description, BOOLEAN);
+ auto BCO =
+ std::make_unique<BaseConfigurationOption>(Name, Description, BOOLEAN);
BCO->setBool(DefaultValue);
- IConf.addBaseChoice(BCO);
+ IConf.addBaseChoice(BCO.get());
return BCO;
}
-BaseConfigurationOption *BaseConfigurationOption::createStringOption(
- InstrumentationConfig &IConf, StringRef Name, StringRef Description,
- StringRef DefaultValue) {
- auto *BCO = new BaseConfigurationOption(Name, Description, STRING);
+std::unique_ptr<BaseConfigurationOption>
+BaseConfigurationOption::createStringOption(InstrumentationConfig &IConf,
+ StringRef Name,
+ StringRef Description,
+ StringRef DefaultValue) {
+ auto BCO =
+ std::make_unique<BaseConfigurationOption>(Name, Description, STRING);
BCO->setString(DefaultValue);
- IConf.addBaseChoice(BCO);
+ IConf.addBaseChoice(BCO.get());
return BCO;
}
More information about the llvm-commits
mailing list