Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SLTozer committed May 2, 2024
1 parent 45a8d28 commit a8fed21
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 88 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/IR/DebugProgramInstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ void DbgVariableRecord::setKillLocation() {
}

bool DbgVariableRecord::isKillLocation() const {
return (getNumVariableLocationOps() == 0 &&
return (!hasArgList() && isa<MDNode>(getRawLocation())) ||
(getNumVariableLocationOps() == 0 &&
!getExpression()->isComplex()) ||
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
}
Expand Down
50 changes: 3 additions & 47 deletions llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace {
// by DbgVariableRecords, the dbg.value replacement.
TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
Expand Down Expand Up @@ -101,14 +99,10 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
EXPECT_TRUE(RetInst->hasDbgRecords());
auto Range2 = RetInst->getDbgRecordRange();
EXPECT_EQ(std::distance(Range2.begin(), Range2.end()), 1u);

UseNewDbgInfoFormat = false;
}

TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"---(
define dso_local void @func() #0 !dbg !10 {
%1 = alloca i32, align 4
Expand Down Expand Up @@ -146,8 +140,6 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
)---");
ASSERT_TRUE(M);

M->convertToNewDbgValues();

Function *F = M->getFunction("func");

BasicBlock &BB = F->getEntryBlock();
Expand All @@ -157,14 +149,10 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
BasicBlock &BBBefore = F->getEntryBlock();
auto I2 = std::prev(BBBefore.end(), 2);
ASSERT_TRUE(I2->hasDbgRecords());

UseNewDbgInfoFormat = false;
}

TEST(BasicBlockDbgInfoTest, MarkerOperations) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
Expand Down Expand Up @@ -289,14 +277,10 @@ TEST(BasicBlockDbgInfoTest, MarkerOperations) {

// Teardown,
Instr1->insertBefore(BB, BB.begin());

UseNewDbgInfoFormat = false;
}

TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
%b = add i16 %a, 1, !dbg !11
Expand Down Expand Up @@ -396,14 +380,10 @@ TEST(BasicBlockDbgInfoTest, HeadBitOperations) {
DInst->DebugMarker->StoredDbgRecords.empty());
EXPECT_FALSE(CInst->DebugMarker->StoredDbgRecords.empty());
EXPECT_EQ(&*BB.begin(), CInst);

UseNewDbgInfoFormat = false;
}

TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
%b = add i16 %a, 1, !dbg !11
Expand Down Expand Up @@ -473,8 +453,6 @@ TEST(BasicBlockDbgInfoTest, InstrDbgAccess) {
CInst->dropOneDbgRecord(DVR1);
EXPECT_FALSE(CInst->hasDbgRecords());
EXPECT_EQ(CInst->DebugMarker->StoredDbgRecords.size(), 0u);

UseNewDbgInfoFormat = false;
}

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

void SetUp() override {
OldDbgInfoFormat = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = true;
M = parseIR(C, SpliceTestIR.c_str());

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

void TearDown() override { UseNewDbgInfoFormat = false; }
void TearDown() override { UseNewDbgInfoFormat = OldDbgInfoFormat; }

bool InstContainsDbgVariableRecord(Instruction *I, DbgVariableRecord *DVR) {
for (DbgRecord &D : I->getDbgRecordRange()) {
Expand Down Expand Up @@ -1176,8 +1156,6 @@ metadata !9, metadata !DIExpression()), !dbg !11 Dest %c = add i16 %b, 1,
// then the trailing DbgVariableRecords should get flushed back out.
TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1222,8 +1200,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
Instruction *BInst = &*Entry.begin();
ASSERT_TRUE(BInst->DebugMarker);
EXPECT_EQ(BInst->DebugMarker->StoredDbgRecords.size(), 1u);

UseNewDbgInfoFormat = false;
}

// When we remove instructions from the program, adjacent DbgVariableRecords
Expand All @@ -1232,8 +1208,6 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceTrailing) {
// dbg.values. Test that this can be replicated correctly by DbgVariableRecords
TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1303,16 +1277,12 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsert) {
EXPECT_EQ(std::distance(R4.begin(), R4.end()), 1u);
auto R5 = RetInst->getDbgRecordRange();
EXPECT_EQ(std::distance(R5.begin(), R5.end()), 1u);

UseNewDbgInfoFormat = false;
}

// Test instruction removal and re-insertion, this time with one
// DbgVariableRecord that should hop up one instruction.
TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1377,8 +1347,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
EXPECT_FALSE(RetInst->hasDbgRecords());
auto R3 = AddInst->getDbgRecordRange();
EXPECT_EQ(std::distance(R3.begin(), R3.end()), 1u);

UseNewDbgInfoFormat = false;
}

// Similar to the above, what if we splice into an empty block with debug-info,
Expand All @@ -1387,8 +1355,6 @@ TEST(BasicBlockDbgInfoTest, RemoveInstAndReinsertForOneDbgVariableRecord) {
// of the i16 0 dbg.value.
TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1448,16 +1414,12 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty1) {

// No trailing DbgVariableRecords in the entry block now.
EXPECT_EQ(Entry.getTrailingDbgRecords(), nullptr);

UseNewDbgInfoFormat = false;
}

// Similar test again, but this time: splice the contents of exit into entry,
// with the intention of leaving the first dbg.value (i16 0) behind.
TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1521,16 +1483,12 @@ TEST(BasicBlockDbgInfoTest, DbgSpliceToEmpty2) {
EXPECT_FALSE(Exit.getTrailingDbgRecords()->empty());
Exit.getTrailingDbgRecords()->eraseFromParent();
Exit.deleteTrailingDbgRecords();

UseNewDbgInfoFormat = false;
}

// What if we moveBefore end() -- there might be no debug-info there, in which
// case we shouldn't crash.
TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
LLVMContext C;
UseNewDbgInfoFormat = true;

std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
entry:
Expand Down Expand Up @@ -1572,8 +1530,6 @@ TEST(BasicBlockDbgInfoTest, DbgMoveToEnd) {
EXPECT_EQ(Entry.getTrailingDbgRecords(), nullptr);
EXPECT_EQ(Exit.getTrailingDbgRecords(), nullptr);
EXPECT_FALSE(Ret->hasDbgRecords());

UseNewDbgInfoFormat = false;
}

} // End anonymous namespace.
55 changes: 30 additions & 25 deletions llvm/unittests/IR/DebugInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ TEST(StripTest, LoopMetadata) {
EXPECT_FALSE(BrokenDebugInfo);
}

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

// Find the dbg.value using %b.
SmallVector<DbgValueInst *, 1> DVIs;
findDbgValues(DVIs, &I);
SmallVector<DbgVariableRecord *, 1> DVRs;
findDbgValues(DVIs, &I, &DVRs);

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

TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {
Expand Down Expand Up @@ -228,8 +229,8 @@ TEST(DbgVariableIntrinsic, EmptyMDIsKillLocation) {

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

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

SmallVector<DbgValueInst *, 2> DVIs;
Expand Down Expand Up @@ -513,14 +514,15 @@ TEST(DbgAssignIntrinsicTest, replaceVariableLocationOp) {
Value *V1 = Fun.getArg(0);
Value *P1 = Fun.getArg(1);
Value *P2 = Fun.getArg(2);
DbgAssignIntrinsic *DAI = cast<DbgAssignIntrinsic>(Fun.begin()->begin());
ASSERT_TRUE(V1 == DAI->getVariableLocationOp(0));
ASSERT_TRUE(P1 == DAI->getAddress());
DbgVariableRecord *DbgAssign =
cast<DbgVariableRecord>(&*Fun.front().front().getDbgRecordRange().begin());
ASSERT_TRUE(V1 == DbgAssign->getVariableLocationOp(0));
ASSERT_TRUE(P1 == DbgAssign->getAddress());

#define TEST_REPLACE(Old, New, ExpectedValue, ExpectedAddr) \
DAI->replaceVariableLocationOp(Old, New); \
EXPECT_EQ(DAI->getVariableLocationOp(0), ExpectedValue); \
EXPECT_EQ(DAI->getAddress(), ExpectedAddr);
DbgAssign->replaceVariableLocationOp(Old, New); \
EXPECT_EQ(DbgAssign->getVariableLocationOp(0), ExpectedValue); \
EXPECT_EQ(DbgAssign->getAddress(), ExpectedAddr);

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

// Replace address only, value uses a DIArgList.
// Value = {DIArgList(V1)}, Addr = P1.
DAI->setRawLocation(DIArgList::get(C, ValueAsMetadata::get(V1)));
DAI->setExpression(DIExpression::get(
DbgAssign->setRawLocation(DIArgList::get(C, ValueAsMetadata::get(V1)));
DbgAssign->setExpression(DIExpression::get(
C, {dwarf::DW_OP_LLVM_arg, 0, dwarf::DW_OP_stack_value}));
TEST_REPLACE(/*Old*/ P1, /*New*/ P2, /*Value*/ V1, /*Address*/ P2);
#undef TEST_REPLACE
Expand Down Expand Up @@ -618,11 +620,11 @@ TEST(AssignmentTrackingTest, Utils) {
//
// Check there are two llvm.dbg.assign intrinsics linked to Alloca.
auto CheckFun1Mapping = [&Alloca]() {
auto Markers = at::getAssignmentMarkers(&Alloca);
auto Markers = at::getDVRAssignmentMarkers(&Alloca);
EXPECT_TRUE(std::distance(Markers.begin(), Markers.end()) == 2);
// Check those two entries are distinct.
DbgAssignIntrinsic *First = *Markers.begin();
DbgAssignIntrinsic *Second = *std::next(Markers.begin());
DbgVariableRecord *First = *Markers.begin();
DbgVariableRecord *Second = *std::next(Markers.begin());
EXPECT_NE(First, Second);

// Check that we can get back to Alloca from each llvm.dbg.assign.
Expand Down Expand Up @@ -658,7 +660,7 @@ TEST(AssignmentTrackingTest, Utils) {
DIAssignID *Fun2ID = cast_or_null<DIAssignID>(
Fun2Alloca.getMetadata(LLVMContext::MD_DIAssignID));
EXPECT_NE(New, Fun2ID);
auto Fun2Markers = at::getAssignmentMarkers(&Fun2Alloca);
auto Fun2Markers = at::getDVRAssignmentMarkers(&Fun2Alloca);
ASSERT_TRUE(std::distance(Fun2Markers.begin(), Fun2Markers.end()) == 1);
auto Fun2Insts = at::getAssignmentInsts(*Fun2Markers.begin());
ASSERT_TRUE(std::distance(Fun2Insts.begin(), Fun2Insts.end()) == 1);
Expand All @@ -667,10 +669,10 @@ TEST(AssignmentTrackingTest, Utils) {
// 3. Check that deleting dbg.assigns from a specific instruction works.
Instruction &Fun3Alloca =
*M->getFunction("fun3")->getEntryBlock().getFirstNonPHIOrDbg();
auto Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
auto Fun3Markers = at::getDVRAssignmentMarkers(&Fun3Alloca);
ASSERT_TRUE(std::distance(Fun3Markers.begin(), Fun3Markers.end()) == 1);
at::deleteAssignmentMarkers(&Fun3Alloca);
Fun3Markers = at::getAssignmentMarkers(&Fun3Alloca);
Fun3Markers = at::getDVRAssignmentMarkers(&Fun3Alloca);
EXPECT_EQ(Fun3Markers.empty(), true);

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

TEST(IRBuilder, GetSetInsertionPointWithEmptyBasicBlock) {
Expand Down Expand Up @@ -767,12 +769,12 @@ TEST(AssignmentTrackingTest, InstrMethods) {
// Use SetVectors to check that the attachments and markers are unique
// (another test requirement).
SetVector<Metadata *> OrigIDs;
SetVector<DbgAssignIntrinsic *> Markers;
SetVector<DbgVariableRecord *> Markers;
for (const Instruction *SI : Stores) {
Metadata *ID = SI->getMetadata(LLVMContext::MD_DIAssignID);
ASSERT_TRUE(OrigIDs.insert(ID));
ASSERT_TRUE(ID != nullptr);
auto Range = at::getAssignmentMarkers(SI);
auto Range = at::getDVRAssignmentMarkers(SI);
ASSERT_TRUE(std::distance(Range.begin(), Range.end()) == 1);
ASSERT_TRUE(Markers.insert(*Range.begin()));
}
Expand Down Expand Up @@ -865,6 +867,8 @@ TEST(AssignmentTrackingTest, InstrMethods) {
// dbg.values that have been converted to a non-instruction format.
TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
LLVMContext C;
bool OldDbgValueMode = UseNewDbgInfoFormat;
UseNewDbgInfoFormat = false;
std::unique_ptr<Module> M = parseIR(C, R"(
define i16 @f(i16 %a) !dbg !6 {
call void @llvm.dbg.value(metadata i16 %a, metadata !9, metadata !DIExpression()), !dbg !11
Expand Down Expand Up @@ -1039,6 +1043,7 @@ TEST(MetadataTest, ConvertDbgToDbgVariableRecord) {
// The record of those trailing DbgVariableRecords would dangle and cause an
// assertion failure if it lived until the end of the LLVMContext.
ExitBlock->deleteTrailingDbgRecords();
UseNewDbgInfoFormat = OldDbgValueMode;
}

TEST(MetadataTest, DbgVariableRecordConversionRoutines) {
Expand Down
Loading

0 comments on commit a8fed21

Please sign in to comment.