diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /unittests/CodeGen/MachineInstrTest.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'unittests/CodeGen/MachineInstrTest.cpp')
-rw-r--r-- | unittests/CodeGen/MachineInstrTest.cpp | 29 |
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 |