From 28d418b16c6cd4836ad9d8bc8006d3dabe3c5559 Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Thu, 25 May 2023 18:15:11 +0200 Subject: [PATCH] [unittest][codegen] Avoid memory leak in recently added FindDebugLocTest unittest Need to finalize the DIBuilder to avoid leak sanitizer errors like this: Direct leak of 48 byte(s) in 1 object(s) allocated from: #0 0x55c99ea1761d in operator new(unsigned long) #1 0x55c9a518ae49 in operator new #2 0x55c9a518ae49 in llvm::MDTuple::getImpl(...) #3 0x55c9a4f1b1ec in getTemporary #4 0x55c9a4f1b1ec in llvm::DIBuilder::createFunction(...) --- llvm/unittests/CodeGen/MachineBasicBlockTest.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/unittests/CodeGen/MachineBasicBlockTest.cpp b/llvm/unittests/CodeGen/MachineBasicBlockTest.cpp index 3dd22353100c8d..8c9d05d2578d51 100644 --- a/llvm/unittests/CodeGen/MachineBasicBlockTest.cpp +++ b/llvm/unittests/CodeGen/MachineBasicBlockTest.cpp @@ -100,6 +100,9 @@ TEST(FindDebugLocTest, DifferentIterators) { EXPECT_EQ(DL1, MBB.rfindPrevDebugLoc(MI2)); EXPECT_EQ(DL1, MBB.rfindPrevDebugLoc(MI3)); EXPECT_EQ(DL1, MBB.rfindPrevDebugLoc(MBB.instr_rbegin())); + + // Finalize DIBuilder to avoid memory leaks. + DIB.finalize(); } } // end namespace