Skip to content

Commit edd6b1f

Browse files
committed
[VPlan] Don't leak ScalarHeader BasicBlock in unit tests.
1 parent 23e2a04 commit edd6b1f

File tree

3 files changed

+49
-35
lines changed

3 files changed

+49
-35
lines changed

llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
4242

4343
auto TC = std::make_unique<VPValue>();
4444
LLVMContext C;
45-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
46-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
45+
auto *ScalarHeader = BasicBlock::Create(C, "");
46+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
4747
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
4848
VPlan Plan(VPPH, &*TC, VPBB0, ScalarHeaderVPBB);
4949

@@ -62,6 +62,7 @@ TEST(VPDominatorTreeTest, DominanceNoRegionsTest) {
6262
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB2, VPBB3), VPBB1);
6363
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB2, VPBB4), VPBB1);
6464
EXPECT_EQ(VPDT.findNearestCommonDominator(VPBB4, VPBB4), VPBB4);
65+
delete ScalarHeader;
6566
}
6667

6768
static void
@@ -77,7 +78,7 @@ checkDomChildren(VPDominatorTree &VPDT, VPBlockBase *Src,
7778

7879
TEST(VPDominatorTreeTest, DominanceRegionsTest) {
7980
LLVMContext C;
80-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
81+
auto *ScalarHeader = BasicBlock::Create(C, "");
8182
{
8283
// 2 consecutive regions.
8384
// VPBB0
@@ -122,7 +123,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
122123
VPBlockUtils::connectBlocks(R1, R2);
123124

124125
auto TC = std::make_unique<VPValue>();
125-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
126+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
126127
VPBlockUtils::connectBlocks(R2, ScalarHeaderVPBB);
127128
VPlan Plan(VPPH, &*TC, VPBB0, ScalarHeaderVPBB);
128129
VPDominatorTree VPDT;
@@ -204,7 +205,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
204205
VPBlockUtils::connectBlocks(R1, VPBB2);
205206

206207
auto TC = std::make_unique<VPValue>();
207-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
208+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
208209
VPBlockUtils::connectBlocks(VPBB2, ScalarHeaderVPBB);
209210
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
210211
VPDominatorTree VPDT;
@@ -221,6 +222,7 @@ TEST(VPDominatorTreeTest, DominanceRegionsTest) {
221222
checkDomChildren(VPDT, R1BB3, {VPBB2});
222223
checkDomChildren(VPDT, VPBB2, {ScalarHeaderVPBB});
223224
}
225+
delete ScalarHeader;
224226
}
225227

226228
} // namespace

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ TEST(VPInstructionTest, releaseOperandsAtDeletion) {
239239
}
240240
TEST(VPBasicBlockTest, getPlan) {
241241
LLVMContext C;
242-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
242+
auto *ScalarHeader = BasicBlock::Create(C, "");
243243
{
244244
VPBasicBlock *VPPH = new VPBasicBlock("ph");
245245
VPBasicBlock *VPBB1 = new VPBasicBlock();
@@ -258,7 +258,7 @@ TEST(VPBasicBlockTest, getPlan) {
258258
VPBlockUtils::connectBlocks(VPBB3, VPBB4);
259259

260260
auto TC = std::make_unique<VPValue>();
261-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
261+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
262262
VPBlockUtils::connectBlocks(VPBB4, ScalarHeaderVPBB);
263263
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
264264

@@ -280,7 +280,7 @@ TEST(VPBasicBlockTest, getPlan) {
280280
VPBlockUtils::connectBlocks(VPBB1, R1);
281281

282282
auto TC = std::make_unique<VPValue>();
283-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
283+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
284284
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
285285
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
286286

@@ -312,7 +312,7 @@ TEST(VPBasicBlockTest, getPlan) {
312312
VPBlockUtils::connectBlocks(R2, VPBB2);
313313

314314
auto TC = std::make_unique<VPValue>();
315-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
315+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
316316
VPBlockUtils::connectBlocks(R2, ScalarHeaderVPBB);
317317
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
318318

@@ -325,11 +325,12 @@ TEST(VPBasicBlockTest, getPlan) {
325325
EXPECT_EQ(&Plan, R2BB2->getPlan());
326326
EXPECT_EQ(&Plan, VPBB2->getPlan());
327327
}
328+
delete ScalarHeader;
328329
}
329330

330331
TEST(VPBasicBlockTest, TraversingIteratorTest) {
331332
LLVMContext C;
332-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
333+
auto *ScalarHeader = BasicBlock::Create(C, "");
333334
{
334335
// VPBasicBlocks only
335336
// VPBB1
@@ -357,7 +358,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
357358

358359
// Use Plan to properly clean up created blocks.
359360
auto TC = std::make_unique<VPValue>();
360-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
361+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
361362
VPBlockUtils::connectBlocks(VPBB4, ScalarHeaderVPBB);
362363
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
363364
}
@@ -459,7 +460,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
459460

460461
// Use Plan to properly clean up created blocks.
461462
auto TC = std::make_unique<VPValue>();
462-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
463+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
463464
VPBlockUtils::connectBlocks(R2, ScalarHeaderVPBB);
464465
VPlan Plan(VPPH, &*TC, VPBB0, ScalarHeaderVPBB);
465466
}
@@ -544,7 +545,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
544545

545546
// Use Plan to properly clean up created blocks.
546547
auto TC = std::make_unique<VPValue>();
547-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
548+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
548549
VPBlockUtils::connectBlocks(VPBB2, ScalarHeaderVPBB);
549550
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
550551
}
@@ -594,7 +595,7 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
594595

595596
// Use Plan to properly clean up created blocks.
596597
auto TC = std::make_unique<VPValue>();
597-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
598+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
598599
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
599600
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
600601
}
@@ -688,10 +689,11 @@ TEST(VPBasicBlockTest, TraversingIteratorTest) {
688689

689690
// Use Plan to properly clean up created blocks.
690691
auto TC = std::make_unique<VPValue>();
691-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
692+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
692693
VPBlockUtils::connectBlocks(VPBB2, ScalarHeaderVPBB);
693694
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
694695
}
696+
delete ScalarHeader;
695697
}
696698

697699
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -729,8 +731,8 @@ TEST(VPBasicBlockTest, print) {
729731
}
730732

731733
LLVMContext C;
732-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
733-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
734+
auto *ScalarHeader = BasicBlock::Create(C, "");
735+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
734736
VPlan Plan(VPBB0, TC, VPBB1, ScalarHeaderVPBB);
735737
std::string FullDump;
736738
raw_string_ostream OS(FullDump);
@@ -800,6 +802,7 @@ No successors
800802
OS << *I4;
801803
EXPECT_EQ("EMIT vp<%5> = mul vp<%3>, vp<%2>", I4Dump);
802804
}
805+
delete ScalarHeader;
803806
}
804807

805808
TEST(VPBasicBlockTest, printPlanWithVFsAndUFs) {
@@ -814,8 +817,8 @@ TEST(VPBasicBlockTest, printPlanWithVFsAndUFs) {
814817
VPBB1->setName("bb1");
815818

816819
LLVMContext C;
817-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
818-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
820+
auto *ScalarHeader = BasicBlock::Create(C, "");
821+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
819822
VPBlockUtils::connectBlocks(VPBB1, ScalarHeaderVPBB);
820823
VPlan Plan(VPBB0, TC, VPBB1, ScalarHeaderVPBB);
821824
Plan.setName("TestPlan");
@@ -891,6 +894,7 @@ No successors
891894
)";
892895
EXPECT_EQ(ExpectedStr, FullDump);
893896
}
897+
delete ScalarHeader;
894898
}
895899
#endif
896900

@@ -1287,8 +1291,8 @@ TEST(VPRecipeTest, dumpRecipeInPlan) {
12871291
VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
12881292
VPBasicBlock *VPBB1 = new VPBasicBlock();
12891293
LLVMContext C;
1290-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
1291-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
1294+
auto *ScalarHeader = BasicBlock::Create(C, "");
1295+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
12921296
VPBlockUtils::connectBlocks(VPBB1, ScalarHeaderVPBB);
12931297
VPlan Plan(VPBB0, VPBB1, ScalarHeaderVPBB);
12941298

@@ -1352,14 +1356,15 @@ TEST(VPRecipeTest, dumpRecipeInPlan) {
13521356
}
13531357

13541358
delete AI;
1359+
delete ScalarHeader;
13551360
}
13561361

13571362
TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesInPlan) {
13581363
VPBasicBlock *VPBB0 = new VPBasicBlock("preheader");
13591364
VPBasicBlock *VPBB1 = new VPBasicBlock();
13601365
LLVMContext C;
1361-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
1362-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
1366+
auto *ScalarHeader = BasicBlock::Create(C, "");
1367+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
13631368
VPBlockUtils::connectBlocks(VPBB1, ScalarHeaderVPBB);
13641369
VPlan Plan(VPBB0, VPBB1, ScalarHeaderVPBB);
13651370

@@ -1440,6 +1445,7 @@ TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesInPlan) {
14401445
testing::ExitedWithCode(0), "EMIT vp<%2> = mul vp<%1>, vp<%1>");
14411446
}
14421447
delete AI;
1448+
delete ScalarHeader;
14431449
}
14441450

14451451
TEST(VPRecipeTest, dumpRecipeUnnamedVPValuesNotInPlanOrBlock) {

llvm/unittests/Transforms/Vectorize/VPlanVerifierTest.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ TEST(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
3030
VPBlockUtils::connectBlocks(VPBB1, R1);
3131

3232
LLVMContext C;
33-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
34-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
33+
auto *ScalarHeader = BasicBlock::Create(C, "");
34+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
3535
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
3636
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
3737

@@ -43,6 +43,7 @@ TEST(VPVerifierTest, VPInstructionUseBeforeDefSameBB) {
4343
EXPECT_STREQ("Use before def!\n",
4444
::testing::internal::GetCapturedStderr().c_str());
4545
#endif
46+
delete ScalarHeader;
4647
}
4748

4849
TEST(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
@@ -66,8 +67,8 @@ TEST(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
6667

6768
auto TC = std::make_unique<VPValue>();
6869
LLVMContext C;
69-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
70-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
70+
auto *ScalarHeader = BasicBlock::Create(C, "");
71+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
7172
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
7273
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
7374

@@ -79,6 +80,7 @@ TEST(VPVerifierTest, VPInstructionUseBeforeDefDifferentBB) {
7980
EXPECT_STREQ("Use before def!\n",
8081
::testing::internal::GetCapturedStderr().c_str());
8182
#endif
83+
delete ScalarHeader;
8284
}
8385

8486
TEST(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
@@ -112,8 +114,8 @@ TEST(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
112114
VPBB3->setParent(R1);
113115

114116
auto TC = std::make_unique<VPValue>();
115-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
116-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
117+
auto *ScalarHeader = BasicBlock::Create(C, "");
118+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
117119
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
118120
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
119121

@@ -127,6 +129,7 @@ TEST(VPVerifierTest, VPBlendUseBeforeDefDifferentBB) {
127129
#endif
128130

129131
delete Phi;
132+
delete ScalarHeader;
130133
}
131134

132135
TEST(VPVerifierTest, DuplicateSuccessorsOutsideRegion) {
@@ -152,8 +155,8 @@ TEST(VPVerifierTest, DuplicateSuccessorsOutsideRegion) {
152155

153156
auto TC = std::make_unique<VPValue>();
154157
LLVMContext C;
155-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
156-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
158+
auto *ScalarHeader = BasicBlock::Create(C, "");
159+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
157160
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
158161
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
159162

@@ -165,6 +168,7 @@ TEST(VPVerifierTest, DuplicateSuccessorsOutsideRegion) {
165168
EXPECT_STREQ("Multiple instances of the same successor.\n",
166169
::testing::internal::GetCapturedStderr().c_str());
167170
#endif
171+
delete ScalarHeader;
168172
}
169173

170174
TEST(VPVerifierTest, DuplicateSuccessorsInsideRegion) {
@@ -193,8 +197,8 @@ TEST(VPVerifierTest, DuplicateSuccessorsInsideRegion) {
193197

194198
auto TC = std::make_unique<VPValue>();
195199
LLVMContext C;
196-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
197-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
200+
auto *ScalarHeader = BasicBlock::Create(C, "");
201+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
198202
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
199203
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
200204

@@ -206,6 +210,7 @@ TEST(VPVerifierTest, DuplicateSuccessorsInsideRegion) {
206210
EXPECT_STREQ("Multiple instances of the same successor.\n",
207211
::testing::internal::GetCapturedStderr().c_str());
208212
#endif
213+
delete ScalarHeader;
209214
}
210215

211216
TEST(VPVerifierTest, BlockOutsideRegionWithParent) {
@@ -226,8 +231,8 @@ TEST(VPVerifierTest, BlockOutsideRegionWithParent) {
226231

227232
auto TC = std::make_unique<VPValue>();
228233
LLVMContext C;
229-
auto ScalarHeader = std::make_unique<BasicBlock *>(BasicBlock::Create(C, ""));
230-
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(*ScalarHeader);
234+
auto *ScalarHeader = BasicBlock::Create(C, "");
235+
VPIRBasicBlock *ScalarHeaderVPBB = new VPIRBasicBlock(ScalarHeader);
231236
VPBlockUtils::connectBlocks(R1, ScalarHeaderVPBB);
232237
VPlan Plan(VPPH, &*TC, VPBB1, ScalarHeaderVPBB);
233238

@@ -239,6 +244,7 @@ TEST(VPVerifierTest, BlockOutsideRegionWithParent) {
239244
EXPECT_STREQ("Predecessor is not in the same region.\n",
240245
::testing::internal::GetCapturedStderr().c_str());
241246
#endif
247+
delete ScalarHeader;
242248
}
243249

244250
} // namespace

0 commit comments

Comments
 (0)