summaryrefslogtreecommitdiff
path: root/unittests/CodeGen/MachineInstrTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/CodeGen/MachineInstrTest.cpp')
-rw-r--r--unittests/CodeGen/MachineInstrTest.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/unittests/CodeGen/MachineInstrTest.cpp b/unittests/CodeGen/MachineInstrTest.cpp
index aca640ebcf35..6883d3ed63e9 100644
--- a/unittests/CodeGen/MachineInstrTest.cpp
+++ b/unittests/CodeGen/MachineInstrTest.cpp
@@ -14,6 +14,8 @@
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
@@ -244,4 +246,31 @@ TEST(MachineInstrExpressionTraitTest, IsEqualAgreesWithGetHashValue) {
checkHashAndIsEqualMatch(VD2PU, VD2PD);
}
+
+TEST(MachineInstrPrintingTest, DebugLocPrinting) {
+ auto MF = createMachineFunction();
+
+ MCOperandInfo OpInfo{0, 0, MCOI::OPERAND_REGISTER, 0};
+ MCInstrDesc MCID = {0, 1, 1, 0, 0, 0,
+ 0, nullptr, nullptr, &OpInfo, 0, nullptr};
+
+ LLVMContext Ctx;
+ DIFile *DIF = DIFile::getDistinct(Ctx, "filename", "");
+ DISubprogram *DIS = DISubprogram::getDistinct(
+ Ctx, nullptr, "", "", DIF, 0, nullptr, false, false, 0, nullptr, 0, 0, 0,
+ DINode::FlagZero, false, nullptr);
+ DILocation *DIL = DILocation::get(Ctx, 1, 5, DIS);
+ DebugLoc DL(DIL);
+ MachineInstr *MI = MF->CreateMachineInstr(MCID, DL);
+ MI->addOperand(*MF, MachineOperand::CreateReg(0, /*isDef*/ true));
+
+ std::string str;
+ raw_string_ostream OS(str);
+ MI->print(OS);
+ ASSERT_TRUE(
+ StringRef(OS.str()).startswith("$noreg = UNKNOWN debug-location "));
+ ASSERT_TRUE(
+ StringRef(OS.str()).endswith("filename:1:5"));
+}
+
} // end namespace