[llvm] 3f03231 - [CodeGen] Fix ponential memory leak in CodeGenPassBuilderTest (#77864)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 18:58:31 PST 2024


Author: paperchalice
Date: 2024-01-12T10:58:27+08:00
New Revision: 3f032312c17e26be0a356630a062b760b62d3379

URL: https://github.com/llvm/llvm-project/commit/3f032312c17e26be0a356630a062b760b62d3379
DIFF: https://github.com/llvm/llvm-project/commit/3f032312c17e26be0a356630a062b760b62d3379.diff

LOG: [CodeGen] Fix ponential memory leak in CodeGenPassBuilderTest (#77864)

Found by https://lab.llvm.org/buildbot/#/builders/5/builds/40038.

Added: 
    

Modified: 
    llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp b/llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp
index ec324a45b9f9e6..d6ec393155cf09 100644
--- a/llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp
+++ b/llvm/unittests/CodeGen/CodeGenPassBuilderTest.cpp
@@ -46,7 +46,7 @@ class DummyCodeGenPassBuilder
 
 class CodeGenPassBuilderTest : public testing::Test {
 public:
-  LLVMTargetMachine *TM;
+  std::unique_ptr<LLVMTargetMachine> TM;
 
   static void SetUpTestCase() {
     InitializeAllTargets();
@@ -69,8 +69,8 @@ class CodeGenPassBuilderTest : public testing::Test {
       GTEST_SKIP();
 
     TargetOptions Options;
-    TM = static_cast<LLVMTargetMachine *>(
-        TheTarget->createTargetMachine("", "", "", Options, std::nullopt));
+    TM = std::unique_ptr<LLVMTargetMachine>(static_cast<LLVMTargetMachine *>(
+        TheTarget->createTargetMachine("", "", "", Options, std::nullopt)));
     if (!TM)
       GTEST_SKIP();
   }
@@ -85,7 +85,7 @@ TEST_F(CodeGenPassBuilderTest, basic) {
   PassInstrumentationCallbacks PIC;
   DummyCodeGenPassBuilder CGPB(*TM, getCGPassBuilderOption(), &PIC);
   PipelineTuningOptions PTO;
-  PassBuilder PB(TM, PTO, std::nullopt, &PIC);
+  PassBuilder PB(TM.get(), PTO, std::nullopt, &PIC);
 
   PB.registerModuleAnalyses(MAM);
   PB.registerCGSCCAnalyses(CGAM);


        


More information about the llvm-commits mailing list