Skip to content

Conversation

jsji
Copy link
Member

@jsji jsji commented Oct 4, 2025

After refactoring in ed1d954, VocabStorage are being leaked.

After refactoring in ed1d954, VocabStorage are being leaked.
@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Oct 4, 2025
@jsji jsji requested a review from svkeerthy October 4, 2025 18:37
@llvmbot
Copy link
Member

llvmbot commented Oct 4, 2025

@llvm/pr-subscribers-mlgo

@llvm/pr-subscribers-llvm-analysis

Author: Jinsong Ji (jsji)

Changes

After refactoring in ed1d954, VocabStorage are being leaked.


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

2 Files Affected:

  • (modified) llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp (+5)
  • (modified) llvm/unittests/Analysis/IR2VecTest.cpp (+4)
diff --git a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
index 497da8f3fc70b..ec1e848f943be 100644
--- a/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
+++ b/llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
@@ -59,6 +59,11 @@ class FunctionPropertiesAnalysisTest : public testing::Test {
     ir2vec::ArgWeight = 1.0;
   }
 
+  ~FunctionPropertiesAnalysisTest() override {
+    delete IR2VecVocab;
+    IR2VecVocab = nullptr;
+  }
+
 private:
   float OriginalOpcWeight = ir2vec::OpcWeight;
   float OriginalTypeWeight = ir2vec::TypeWeight;
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index d136cb6a316b1..4348d5cee106a 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -319,6 +319,10 @@ class IR2VecTestFixture : public ::testing::Test {
     AddInst = BinaryOperator::CreateAdd(Arg, Const, "add", BB);
     RetInst = ReturnInst::Create(Ctx, AddInst, BB);
   }
+  void TearDown() override {
+    delete V ;
+    V = nullptr;
+  }
 };
 
 TEST_F(IR2VecTestFixture, GetInstVecMap_Symbolic) {

@jsji jsji requested review from Copilot and snehasish October 4, 2025 18:37
@jsji jsji self-assigned this Oct 4, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes memory leaks in IR2Vec unit tests by adding proper cleanup of VocabStorage objects that were being leaked after a previous refactoring (ed1d954).

  • Added TearDown method to IR2VecTestFixture to delete the V pointer and set it to nullptr
  • Added destructor to FunctionPropertiesAnalysisTest to delete IR2VecVocab pointer and set it to nullptr

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
llvm/unittests/Analysis/IR2VecTest.cpp Added TearDown method to properly cleanup VocabStorage pointer V
llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp Added destructor to properly cleanup IR2VecVocab pointer

@jsji jsji requested a review from mtrofin October 4, 2025 18:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jsji jsji requested a review from Copilot October 4, 2025 18:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@boomanaiden154
Copy link
Contributor

#161878 should have already fixed this?

@jsji jsji closed this Oct 5, 2025
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.

3 participants