Skip to content

Conversation

svkeerthy
Copy link
Contributor

Fixing the memory leaks introduced (#158376) in the unit tests of FunctionPropertiesAnalysis and IR2Vec.

@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Oct 3, 2025
@svkeerthy svkeerthy requested review from alinas and kstoimenov October 3, 2025 16:59
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-mlgo

Author: S. VenkataKeerthy (svkeerthy)

Changes

Fixing the memory leaks introduced (#158376) in the unit tests of FunctionPropertiesAnalysis and IR2Vec.


Full diff: https://github.com/llvm/llvm-project/pull/161878.diff

2 Files Affected:

  • (modified) llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp (+2-2)
  • (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+2-2)
diff --git a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
index b6e8567ee514d..0ae6d7c1e31af 100644
--- a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
+++ b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
@@ -47,7 +47,7 @@ class FunctionPropertiesAnalysisTest : public testing::Test {
       return IR2VecVocabAnalysis(std::move(VocabVector));
     });
     IR2VecVocab =
-        new ir2vec::Vocabulary(ir2vec::Vocabulary::createDummyVocabForTest(1));
+        std::make_unique<ir2vec::Vocabulary>(ir2vec::Vocabulary::createDummyVocabForTest(1));
     MAM.registerPass([&] { return PassInstrumentationAnalysis(); });
     FAM.registerPass([&] { return ModuleAnalysisManagerFunctionProxy(MAM); });
     FAM.registerPass([&] { return DominatorTreeAnalysis(); });
@@ -69,7 +69,7 @@ class FunctionPropertiesAnalysisTest : public testing::Test {
   std::unique_ptr<LoopInfo> LI;
   FunctionAnalysisManager FAM;
   ModuleAnalysisManager MAM;
-  ir2vec::Vocabulary *IR2VecVocab;
+  std::unique_ptr<ir2vec::Vocabulary> IR2VecVocab;
 
   void TearDown() override {
     // Restore original IR2Vec weights
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index 743628fffac76..d136cb6a316b1 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -295,7 +295,7 @@ TEST(IR2VecTest, ZeroDimensionEmbedding) {
 // Fixture for IR2Vec tests requiring IR setup.
 class IR2VecTestFixture : public ::testing::Test {
 protected:
-  Vocabulary *V;
+  std::unique_ptr<Vocabulary> V;
   LLVMContext Ctx;
   std::unique_ptr<Module> M;
   Function *F = nullptr;
@@ -304,7 +304,7 @@ class IR2VecTestFixture : public ::testing::Test {
   Instruction *RetInst = nullptr;
 
   void SetUp() override {
-    V = new Vocabulary(Vocabulary::createDummyVocabForTest(2));
+    V = std::make_unique<Vocabulary>(Vocabulary::createDummyVocabForTest(2));
 
     // Setup IR
     M = std::make_unique<Module>("TestM", Ctx);

@svkeerthy svkeerthy requested a review from mtrofin October 3, 2025 17:00
Copy link

github-actions bot commented Oct 3, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@alinas alinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@alinas alinas merged commit 616e523 into main Oct 3, 2025
9 checks passed
@alinas alinas deleted the users/svkeerthy/10-03-memory-leak-fix branch October 3, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding mlgo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants