[llvm] [DomTreeUpdater] Fix use after free in unittests (PR #97133)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 18:32:03 PDT 2024


https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/97133

In #96851, the unit test contains use after free, which triggers sanitizer error.

>From c77fe0d2a8073a1650bac2ee939f9cfe08f9e3ea Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Sat, 29 Jun 2024 09:29:40 +0800
Subject: [PATCH] [DomTreeUpdater] Fix use after free in unittests

---
 llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp b/llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp
index e123ba847e622..ee74b8a540542 100644
--- a/llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp
+++ b/llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp
@@ -179,7 +179,6 @@ body:             |
   DTU.deleteBB(&*BB4);
   EXPECT_EQ(BB1->succ_size(), 1u);
   ASSERT_TRUE(DT.dominates(&*BB1, &*BB2));
-  ASSERT_EQ(DT.getNode(&*BB4), nullptr);
 }
 
 TEST_F(MachineDomTreeUpdaterTest, LazyUpdateBasicOperations) {
@@ -268,9 +267,9 @@ body:             |
   ASSERT_TRUE(DT.dominates(&*BB1, &*BB4));
   BB1->removeSuccessor(&*BB4);
   DTU.deleteBB(&*BB4);
+  ASSERT_TRUE(DTU.hasPendingDeletedBB());
   EXPECT_EQ(BB1->succ_size(), 1u);
   ASSERT_TRUE(DT.dominates(&*BB1, &*BB2));
   ASSERT_NE(DT.getNode(&*BB4), nullptr);
   DTU.flush();
-  ASSERT_EQ(DT.getNode(&*BB4), nullptr);
 }



More information about the llvm-commits mailing list