Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a8fed21

Browse files
committedMay 2, 2024
Fix broken tests
1 parent 45a8d28 commit a8fed21

File tree

6 files changed

+44
-88
lines changed

6 files changed

+44
-88
lines changed
 

‎llvm/lib/IR/DebugProgramInstruction.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ void DbgVariableRecord::setKillLocation() {
366366
}
367367

368368
bool DbgVariableRecord::isKillLocation() const {
369-
return (getNumVariableLocationOps() == 0 &&
369+
return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
370+
(getNumVariableLocationOps() == 0 &&
370371
!getExpression()->isComplex()) ||
371372
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
372373
}

‎llvm/unittests/IR/BasicBlockDbgInfoTest.cpp

+3-47
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ namespace {
4444
// by DbgVariableRecords, the dbg.value replacement.
4545
TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
4646
LLVMContext C;
47-
UseNewDbgInfoFormat = true;
48-
4947
std::unique_ptr<Module> M = parseIR(C, R"(
5048
define i16 @f(i16 %a) !dbg !6 {
5149
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -101,14 +99,10 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
10199
EXPECT_TRUE(RetInst->hasDbgRecords());
102100
auto Range2 = RetInst->getDbgRecordRange();
103101
EXPECT_EQ(std::distance(Range2.begin(), Range2.end()), 1u);
104-
105-
UseNewDbgInfoFormat = false;
106102
}
107103

108104
TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
109105
LLVMContext C;
110-
UseNewDbgInfoFormat = true;
111-
112106
std::unique_ptr<Module> M = parseIR(C, R"---(
113107
define dso_local void @func() #0 !dbg !10 {
114108
%1 = alloca i32, align 4
@@ -146,8 +140,6 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
146140
)---");
147141
ASSERT_TRUE(M);
148142

149-
M->convertToNewDbgValues();
150-
151143
Function *F = M->getFunction("func");
152144

153145
BasicBlock &BB = F->getEntryBlock();
@@ -157,14 +149,10 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
157149
BasicBlock &BBBefore = F->getEntryBlock();
158150
auto I2 = std::prev(BBBefore.end(), 2);
159151
ASSERT_TRUE(I2->hasDbgRecords());
160-
161-
UseNewDbgInfoFormat = false;
162152
}
163153

164154
TEST(BasicBlockDbgInfoTest, MarkerOperations) {
165155
LLVMContext C;
166-
UseNewDbgInfoFormat = true;
167-
168156
std::unique_ptr<Module> M = parseIR(C, R"(
169157
define i16 @f(i16 %a) !dbg !6 {
170158
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -289,14 +277,10 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {
289277

290278
// Teardown,
291279
Instr1->insertBefore(BB, BB.begin());
292-
293-
UseNewDbgInfoFormat = false;
294280
}
295281

296282
TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
297283
LLVMContext C;
298-
UseNewDbgInfoFormat = true;
299-
300284
std::unique_ptr<Module> M = parseIR(C, R"(
301285
define i16 @f(i16 %a) !dbg !6 {
302286
%b = add i16 %a, 1, !dbg !11
@@ -396,14 +380,10 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
396380
DInst->DebugMarker->StoredDbgRecords.empty());
397381
EXPECT_FALSE(CInst->DebugMarker->StoredDbgRecords.empty());
398382
EXPECT_EQ(&*BB.begin(), CInst);
399-
400-
UseNewDbgInfoFormat = false;
401383
}
402384

403385
TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
404386
LLVMContext C;
405-
UseNewDbgInfoFormat = true;
406-
407387
std::unique_ptr<Module> M = parseIR(C, R"(
408388
define i16 @f(i16 %a) !dbg !6 {
409389
%b = add i16 %a, 1, !dbg !11
@@ -473,8 +453,6 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
473453
CInst->dropOneDbgRecord(DVR1);
474454
EXPECT_FALSE(CInst->hasDbgRecords());
475455
EXPECT_EQ(CInst->DebugMarker->StoredDbgRecords.size(), 0u);
476-
477-
UseNewDbgInfoFormat = false;
478456
}
479457

480458
/* Let's recall the big illustration from BasicBlock::spliceDebugInfo:
@@ -565,8 +543,10 @@ class DbgSpliceTest : public ::testing::Test {
565543
BasicBlock::iterator Dest, First, Last;
566544
Instruction *BInst, *Branch, *CInst;
567545
DbgVariableRecord *DVRA, *DVRB, *DVRConst;
546+
bool OldDbgInfoFormat;
568547

569548
void SetUp() override {
549+
OldDbgInfoFormat = UseNewDbgInfoFormat;
570550
UseNewDbgInfoFormat = true;
571551
M = parseIR(C, SpliceTestIR.c_str());
572552

@@ -588,7 +568,7 @@ class DbgSpliceTest : public ::testing::Test {
588568
cast<DbgVariableRecord>(&*CInst->DebugMarker->StoredDbgRecords.begin());
589569
}
590570

591-
void TearDown() override { UseNewDbgInfoFormat = false; }
571+
void TearDown() override { UseNewDbgInfoFormat = OldDbgInfoFormat; }
592572

593573
bool InstContainsDbgVariableRecord(Instruction *I, DbgVariableRecord *DVR) {
594574
for (DbgRecord &D : I->getDbgRecordRange()) {
@@ -1176,8 +1156,6 @@ metadata !9, metadata !DIExpression()), !dbg !11 Dest %c = add i16 %b, 1,
11761156
// then the trailing DbgVariableRecords should get flushed back out.
11771157
TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
11781158
LLVMContext C;
1179-
UseNewDbgInfoFormat = true;
1180-
11811159
std::unique_ptr<Module> M = parseIR(C, R"(
11821160
define i16 @f(i16 %a) !dbg !6 {
11831161
entry:
@@ -1222,8 +1200,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
12221200
Instruction *BInst = &*Entry.begin();
12231201
ASSERT_TRUE(BInst->DebugMarker);
12241202
EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 1u);
1225-
1226-
UseNewDbgInfoFormat = false;
12271203
}
12281204

12291205
// When we remove instructions from the program, adjacent DbgVariableRecords
@@ -1232,8 +1208,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
12321208
// dbg.values. Test that this can be replicated correctly by DbgVariableRecords
12331209
TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
12341210
LLVMContext C;
1235-
UseNewDbgInfoFormat = true;
1236-
12371211
std::unique_ptr<Module> M = parseIR(C, R"(
12381212
define i16 @f(i16 %a) !dbg !6 {
12391213
entry:
@@ -1303,16 +1277,12 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
13031277
EXPECT_EQ(std::distance(R4.begin(), R4.end()), 1u);
13041278
auto R5 = RetInst->getDbgRecordRange();
13051279
EXPECT_EQ(std::distance(R5.begin(), R5.end()), 1u);
1306-
1307-
UseNewDbgInfoFormat = false;
13081280
}
13091281

13101282
// Test instruction removal and re-insertion, this time with one
13111283
// DbgVariableRecord that should hop up one instruction.
13121284
TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
13131285
LLVMContext C;
1314-
UseNewDbgInfoFormat = true;
1315-
13161286
std::unique_ptr<Module> M = parseIR(C, R"(
13171287
define i16 @f(i16 %a) !dbg !6 {
13181288
entry:
@@ -1377,8 +1347,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
13771347
EXPECT_FALSE(RetInst->hasDbgRecords());
13781348
auto R3 = AddInst->getDbgRecordRange();
13791349
EXPECT_EQ(std::distance(R3.begin(), R3.end()), 1u);
1380-
1381-
UseNewDbgInfoFormat = false;
13821350
}
13831351

13841352
// Similar to the above, what if we splice into an empty block with debug-info,
@@ -1387,8 +1355,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
13871355
// of the i16 0 dbg.value.
13881356
TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
13891357
LLVMContext C;
1390-
UseNewDbgInfoFormat = true;
1391-
13921358
std::unique_ptr<Module> M = parseIR(C, R"(
13931359
define i16 @f(i16 %a) !dbg !6 {
13941360
entry:
@@ -1448,16 +1414,12 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
14481414

14491415
// No trailing DbgVariableRecords in the entry block now.
14501416
EXPECT_EQ(Entry.getTrailingDbgRecords(), nullptr);
1451-
1452-
UseNewDbgInfoFormat = false;
14531417
}
14541418

14551419
// Similar test again, but this time: splice the contents of exit into entry,
14561420
// with the intention of leaving the first dbg.value (i16 0) behind.
14571421
TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
14581422
LLVMContext C;
1459-
UseNewDbgInfoFormat = true;
1460-
14611423
std::unique_ptr<Module> M = parseIR(C, R"(
14621424
define i16 @f(i16 %a) !dbg !6 {
14631425
entry:
@@ -1521,16 +1483,12 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
15211483
EXPECT_FALSE(Exit.getTrailingDbgRecords()->empty());
15221484
Exit.getTrailingDbgRecords()->eraseFromParent();
15231485
Exit.deleteTrailingDbgRecords();
1524-
1525-
UseNewDbgInfoFormat = false;
15261486
}
15271487

15281488
// What if we moveBefore end() -- there might be no debug-info there, in which
15291489
// case we shouldn't crash.
15301490
TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
15311491
LLVMContext C;
1532-
UseNewDbgInfoFormat = true;
1533-
15341492
std::unique_ptr<Module> M = parseIR(C, R"(
15351493
define i16 @f(i16 %a) !dbg !6 {
15361494
entry:
@@ -1572,8 +1530,6 @@ TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
15721530
EXPECT_EQ(Entry.getTrailingDbgRecords(), nullptr);
15731531
EXPECT_EQ(Exit.getTrailingDbgRecords(), nullptr);
15741532
EXPECT_FALSE(Ret->hasDbgRecords());
1575-
1576-
UseNewDbgInfoFormat = false;
15771533
}
15781534

15791535
} // End anonymous namespace.

‎llvm/unittests/IR/DebugInfoTest.cpp

+30-25
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ TEST(StripTest, LoopMetadata) {
154154
EXPECT_FALSE(BrokenDebugInfo);
155155
}
156156

157-
TEST(MetadataTest, DeleteInstUsedByDbgValue) {
157+
TEST(MetadataTest, DeleteInstUsedByDbgRecord) {
158158
LLVMContext C;
159159
std::unique_ptr<Module> M = parseIR(C, R"(
160160
define i16 @f(i16 %a) !dbg !6 {
@@ -185,12 +185,13 @@ TEST(MetadataTest, DeleteInstUsedByDbgValue) {
185185

186186
// Find the dbg.value using %b.
187187
SmallVector<DbgValueInst *, 1> DVIs;
188-
findDbgValues(DVIs, &I);
188+
SmallVector<DbgVariableRecord *, 1> DVRs;
189+
findDbgValues(DVIs, &I, &DVRs);
189190

190191
// Delete %b. The dbg.value should now point to undef.
191192
I.eraseFromParent();
192-
EXPECT_EQ(DVIs[0]->getNumVariableLocationOps(), 1u);
193-
EXPECT_TRUE(isa<UndefValue>(DVIs[0]->getValue(0)));
193+
EXPECT_EQ(DVRs[0]->getNumVariableLocationOps(), 1u);
194+
EXPECT_TRUE(isa<UndefValue>(DVRs[0]->getValue(0)));
194195
}
195196

196197
TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
@@ -228,8 +229,8 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
228229

229230
// Get the dbg.declare.
230231
Function &F = *cast<Function>(M->getNamedValue("fun"));
231-
DbgVariableIntrinsic *DbgDeclare =
232-
cast<DbgVariableIntrinsic>(&F.front().front());
232+
DbgVariableRecord *DbgDeclare =
233+
cast<DbgVariableRecord>(&*F.front().front().getDbgRecordRange().begin());
233234
// Check that this form counts as a "no location" marker.
234235
EXPECT_TRUE(DbgDeclare->isKillLocation());
235236
}
@@ -287,6 +288,8 @@ TEST(MetadataTest, DeleteInstUsedByDbgVariableRecord) {
287288
// Ensure that the order of dbg.value intrinsics returned by findDbgValues, and
288289
// their corresponding DbgVariableRecord representation, are consistent.
289290
TEST(MetadataTest, OrderingOfDbgVariableRecords) {
291+
bool OldDbgValueMode = UseNewDbgInfoFormat;
292+
UseNewDbgInfoFormat = false;
290293
LLVMContext C;
291294
std::unique_ptr<Module> M = parseIR(C, R"(
292295
define i16 @f(i16 %a) !dbg !6 {
@@ -314,8 +317,6 @@ TEST(MetadataTest, OrderingOfDbgVariableRecords) {
314317
!12 = !DILocalVariable(name: "bar", scope: !6, file: !1, line: 1, type: !10)
315318
)");
316319

317-
bool OldDbgValueMode = UseNewDbgInfoFormat;
318-
UseNewDbgInfoFormat = true;
319320
Instruction &I = *M->getFunction("f")->getEntryBlock().getFirstNonPHI();
320321

321322
SmallVector<DbgValueInst *, 2> DVIs;
@@ -513,14 +514,15 @@ TEST(DbgAssignIntrinsicTest, replaceVariableLocationOp) {
513514
Value *V1 = Fun.getArg(0);
514515
Value *P1 = Fun.getArg(1);
515516
Value *P2 = Fun.getArg(2);
516-
DbgAssignIntrinsic *DAI = cast<DbgAssignIntrinsic>(Fun.begin()->begin());
517-
ASSERT_TRUE(V1 == DAI->getVariableLocationOp(0));
518-
ASSERT_TRUE(P1 == DAI->getAddress());
517+
DbgVariableRecord *DbgAssign =
518+
cast<DbgVariableRecord>(&*Fun.front().front().getDbgRecordRange().begin());
519+
ASSERT_TRUE(V1 == DbgAssign->getVariableLocationOp(0));
520+
ASSERT_TRUE(P1 == DbgAssign->getAddress());
519521

520522
#define TEST_REPLACE(Old, New, ExpectedValue, ExpectedAddr) \
521-
DAI->replaceVariableLocationOp(Old, New); \
522-
EXPECT_EQ(DAI->getVariableLocationOp(0), ExpectedValue); \
523-
EXPECT_EQ(DAI->getAddress(), ExpectedAddr);
523+
DbgAssign->replaceVariableLocationOp(Old, New); \
524+
EXPECT_EQ(DbgAssign->getVariableLocationOp(0), ExpectedValue); \
525+
EXPECT_EQ(DbgAssign->getAddress(), ExpectedAddr);
524526

525527
// Replace address only.
526528
TEST_REPLACE(/*Old*/ P1, /*New*/ P2, /*Value*/ V1, /*Address*/ P2);
@@ -531,8 +533,8 @@ TEST(DbgAssignIntrinsicTest, replaceVariableLocationOp) {
531533

532534
// Replace address only, value uses a DIArgList.
533535
// Value = {DIArgList(V1)}, Addr = P1.
534-
DAI->setRawLocation(DIArgList::get(C, ValueAsMetadata::get(V1)));
535-
DAI->setExpression(DIExpression::get(
536+
DbgAssign->setRawLocation(DIArgList::get(C, ValueAsMetadata::get(V1)));
537+
DbgAssign->setExpression(DIExpression::get(
536538
C, {dwarf::DW_OP_LLVM_arg, 0, dwarf::DW_OP_stack_value}));
537539
TEST_REPLACE(/*Old*/ P1, /*New*/ P2, /*Value*/ V1, /*Address*/ P2);
538540
#undef TEST_REPLACE
@@ -618,11 +620,11 @@ TEST(AssignmentTrackingTest, Utils) {
618620
//
619621
// Check there are two llvm.dbg.assign intrinsics linked to Alloca.
620622
auto CheckFun1Mapping = [&Alloca]() {
621-
auto Markers = at::getAssignmentMarkers(&Alloca);
623+
auto Markers = at::getDVRAssignmentMarkers(&Alloca);
622624
EXPECT_TRUE(std::distance(Markers.begin(), Markers.end()) == 2);
623625
// Check those two entries are distinct.
624-
DbgAssignIntrinsic *First = *Markers.begin();
625-
DbgAssignIntrinsic *Second = *std::next(Markers.begin());
626+
DbgVariableRecord *First = *Markers.begin();
627+
DbgVariableRecord *Second = *std::next(Markers.begin());
626628
EXPECT_NE(First, Second);
627629

628630
// Check that we can get back to Alloca from each llvm.dbg.assign.
@@ -658,7 +660,7 @@ TEST(AssignmentTrackingTest, Utils) {
658660
DIAssignID *Fun2ID = cast_or_null<DIAssignID>(
659661
Fun2Alloca.getMetadata(LLVMContext::MD_DIAssignID));
660662
EXPECT_NE(New, Fun2ID);
661-
auto Fun2Markers = at::getAssignmentMarkers(&Fun2Alloca);
663+
auto Fun2Markers = at::getDVRAssignmentMarkers(&Fun2Alloca);
662664
ASSERT_TRUE(std::distance(Fun2Markers.begin(), Fun2Markers.end()) == 1);
663665
auto Fun2Insts = at::getAssignmentInsts(*Fun2Markers.begin());
664666
ASSERT_TRUE(std::distance(Fun2Insts.begin(), Fun2Insts.end()) == 1);
@@ -667,10 +669,10 @@ TEST(AssignmentTrackingTest, Utils) {
667669
// 3. Check that deleting dbg.assigns from a specific instruction works.
668670
Instruction &Fun3Alloca =
669671
*M->getFunction("fun3")->getEntryBlock().getFirstNonPHIOrDbg();
670-
auto Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
672+
auto Fun3Markers = at::getDVRAssignmentMarkers(&Fun3Alloca);
671673
ASSERT_TRUE(std::distance(Fun3Markers.begin(), Fun3Markers.end()) == 1);
672674
at::deleteAssignmentMarkers(&Fun3Alloca);
673-
Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
675+
Fun3Markers = at::getDVRAssignmentMarkers(&Fun3Alloca);
674676
EXPECT_EQ(Fun3Markers.empty(), true);
675677

676678
// 4. Check that deleting works and applies only to the target function.
@@ -681,7 +683,7 @@ TEST(AssignmentTrackingTest, Utils) {
681683
// llvm.dbg.assign.
682684
EXPECT_EQ(Fun2ID, cast_or_null<DIAssignID>(
683685
Fun2Alloca.getMetadata(LLVMContext::MD_DIAssignID)));
684-
EXPECT_FALSE(at::getAssignmentMarkers(&Fun2Alloca).empty());
686+
EXPECT_FALSE(at::getDVRAssignmentMarkers(&Fun2Alloca).empty());
685687
}
686688

687689
TEST(IRBuilder, GetSetInsertionPointWithEmptyBasicBlock) {
@@ -767,12 +769,12 @@ TEST(AssignmentTrackingTest, InstrMethods) {
767769
// Use SetVectors to check that the attachments and markers are unique
768770
// (another test requirement).
769771
SetVector<Metadata *> OrigIDs;
770-
SetVector<DbgAssignIntrinsic *> Markers;
772+
SetVector<DbgVariableRecord *> Markers;
771773
for (const Instruction *SI : Stores) {
772774
Metadata *ID = SI->getMetadata(LLVMContext::MD_DIAssignID);
773775
ASSERT_TRUE(OrigIDs.insert(ID));
774776
ASSERT_TRUE(ID != nullptr);
775-
auto Range = at::getAssignmentMarkers(SI);
777+
auto Range = at::getDVRAssignmentMarkers(SI);
776778
ASSERT_TRUE(std::distance(Range.begin(), Range.end()) == 1);
777779
ASSERT_TRUE(Markers.insert(*Range.begin()));
778780
}
@@ -865,6 +867,8 @@ TEST(AssignmentTrackingTest, InstrMethods) {
865867
// dbg.values that have been converted to a non-instruction format.
866868
TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
867869
LLVMContext C;
870+
bool OldDbgValueMode = UseNewDbgInfoFormat;
871+
UseNewDbgInfoFormat = false;
868872
std::unique_ptr<Module> M = parseIR(C, R"(
869873
define i16 @f(i16 %a) !dbg !6 {
870874
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
@@ -1039,6 +1043,7 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
10391043
// The record of those trailing DbgVariableRecords would dangle and cause an
10401044
// assertion failure if it lived until the end of the LLVMContext.
10411045
ExitBlock->deleteTrailingDbgRecords();
1046+
UseNewDbgInfoFormat = OldDbgValueMode;
10421047
}
10431048

10441049
TEST(MetadataTest, DbgVariableRecordConversionRoutines) {

0 commit comments

Comments
 (0)