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

Thurston Dang via llvm-commits llvm-commits at lists.llvm.org
Fri May 22 15:05:54 PDT 2026


================
@@ -1510,132 +1510,142 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
 
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 TEST_F(VPRecipeTest, dumpRecipeInPlan) {
-  VPlan &Plan = getPlan();
-  VPBasicBlock *VPBB0 = Plan.getEntry();
-  VPBasicBlock *VPBB1 = Plan.createVPBasicBlock("");
-  VPBlockUtils::connectBlocks(VPBB1, Plan.getScalarHeader());
-  VPBlockUtils::connectBlocks(VPBB0, VPBB1);
-
   IntegerType *Int32 = IntegerType::get(C, 32);
+  // AI must outlive VPlan &Plan
   auto *AI = BinaryOperator::CreateAdd(PoisonValue::get(Int32),
                                        PoisonValue::get(Int32));
   AI->setName("a");
-  SmallVector<VPValue *, 2> Args;
-  VPValue *ExtVPV1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
-  VPValue *ExtVPV2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
-  Args.push_back(ExtVPV1);
-  Args.push_back(ExtVPV2);
-  VPWidenRecipe *WidenR = new VPWidenRecipe(*AI, Args);
----------------
thurstond wrote:

> it's not 100% clear to me why the scoping does the right thing, as the returned plan should be owned by VPlanTestBase, which I presume outlives the function? Is there something else that deletes the plan early?

It didn't fix it. I am a small language human and didn't rebuild the ASan tests properly when I tested it earlier 🫣

https://github.com/llvm/llvm-project/pull/199275


More information about the llvm-commits mailing list