[llvm] [RemoveDIs] Fix asan-identified leak in unittest (PR #106723)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 30 05:48:04 PDT 2024


https://github.com/OCHyams created https://github.com/llvm/llvm-project/pull/106723

Fixes issue found here https://github.com/llvm/llvm-project/pull/106691#issuecomment-2320960847

The issue wasn't in the code change itself, just the unittest; the trailing marker wasn't properly cleaned up.

>From a80307d0a271223136e0845571606400fb41b2ee Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Fri, 30 Aug 2024 13:44:42 +0100
Subject: [PATCH] [RemoveDIs] Fix asan-identified leak in unittest

https://github.com/llvm/llvm-project/pull/106691#issuecomment-2320960847
---
 llvm/unittests/IR/BasicBlockDbgInfoTest.cpp | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
index 5615a4493d20a1..5ce14d3f6b9cef 100644
--- a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
+++ b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
@@ -1569,14 +1569,12 @@ TEST(BasicBlockDbgInfoTest, CloneTrailingRecordsToEmptyBlock) {
   // The trailing records should've been absorbed into NewBB.
   EXPECT_FALSE(BB.getTrailingDbgRecords());
   EXPECT_TRUE(NewBB->getTrailingDbgRecords());
-  if (NewBB->getTrailingDbgRecords()) {
-    EXPECT_EQ(
-        llvm::range_size(NewBB->getTrailingDbgRecords()->getDbgRecordRange()),
-        1u);
+  if (DbgMarker *Trailing = NewBB->getTrailingDbgRecords()) {
+    EXPECT_EQ(llvm::range_size(Trailing->getDbgRecordRange()), 1u);
+    // Drop the trailing records now, to prevent a cleanup assertion.
+    Trailing->eraseFromParent();
+    NewBB->deleteTrailingDbgRecords();
   }
-
-  // Drop the trailing records now, to prevent a cleanup assertion.
-  NewBB->deleteTrailingDbgRecords();
 }
 
 } // End anonymous namespace.



More information about the llvm-commits mailing list