[llvm] [NFC] Fix memory leak in IR2Vec tests (PR #161964)
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 4 11:38:24 PDT 2025
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/161964
>From 9e65c6c47d8c6f8ba0df2c7ef74e195a9337a3c5 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 4 Oct 2025 11:33:44 -0700
Subject: [PATCH 1/2] [NFC] Fix memory leak in IR2Vec tests
After refactoring in ed1d9548b5c0, VocabStorage are being leaked.
---
llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp | 5 +++++
llvm/unittests/Analysis/IR2VecTest.cpp | 4 ++++
2 files changed, 9 insertions(+)
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) {
>From 4138a28ec6161c36f53f6f714211df44a0e026ae Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 4 Oct 2025 14:38:16 -0400
Subject: [PATCH 2/2] Update llvm/unittests/Analysis/IR2VecTest.cpp
Co-authored-by: Copilot <175728472+Copilot at users.noreply.github.com>
---
llvm/unittests/Analysis/IR2VecTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/unittests/Analysis/IR2VecTest.cpp b/llvm/unittests/Analysis/IR2VecTest.cpp
index 4348d5cee106a..d5df9a9246c5a 100644
--- a/llvm/unittests/Analysis/IR2VecTest.cpp
+++ b/llvm/unittests/Analysis/IR2VecTest.cpp
@@ -320,7 +320,7 @@ class IR2VecTestFixture : public ::testing::Test {
RetInst = ReturnInst::Create(Ctx, AddInst, BB);
}
void TearDown() override {
- delete V ;
+ delete V;
V = nullptr;
}
};
More information about the llvm-commits
mailing list