[llvm] 65b5880 - [VPlan][test] Fix use-after-free in dumpRecipeInPlan/dumpRecipeUnnamedVPValuesInPlan tests (#199275)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 22 20:47:21 PDT 2026


Author: Thurston Dang
Date: 2026-05-22T20:47:16-07:00
New Revision: 65b58800c50af89c79d7ef7100f555f188f0c979

URL: https://github.com/llvm/llvm-project/commit/65b58800c50af89c79d7ef7100f555f188f0c979
DIFF: https://github.com/llvm/llvm-project/commit/65b58800c50af89c79d7ef7100f555f188f0c979.diff

LOG: [VPlan][test] Fix use-after-free in dumpRecipeInPlan/dumpRecipeUnnamedVPValuesInPlan tests (#199275)

https://github.com/llvm/llvm-project/pull/195891 exposed a
use-after-free in the tests: `BinaryOperator *AI` [*] is deleted prior
to VPlan's destructor, which expects all the operands to still be alive.
This patch fixes the test (suggested by a Florian in
https://github.com/llvm/llvm-project/pull/199252#pullrequestreview-4348337988),
by preemptively detaching AI from the VPlan.

[*] No AI was harmed or used during the creation of this patch.

Added: 
    

Modified: 
    llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 9326acb8269e6..6b1e005f4de57 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1565,6 +1565,9 @@ TEST_F(VPRecipeTest, dumpRecipeInPlan) {
         testing::ExitedWithCode(0), "WIDEN ir<%a> = add ir<1>, ir<2>");
   }
 
+  // Avoid use-after-free of AI when the VPlan destructor is called.
+  WidenR->eraseFromParent();
+
   delete AI;
 }
 
@@ -1636,6 +1639,11 @@ TEST_F(VPRecipeTest, dumpRecipeUnnamedVPValuesInPlan) {
         },
         testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
   }
+
+  // Avoid use-after-free of AI when the VPlan destructor is called.
+  I2->eraseFromParent();
+  I1->eraseFromParent();
+
   delete AI;
 }
 


        


More information about the llvm-commits mailing list