diff options
Diffstat (limited to 'llvm/unittests/CodeGen/MachineInstrTest.cpp')
-rw-r--r-- | llvm/unittests/CodeGen/MachineInstrTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp index 21b5eb6..0f86968 100644 --- a/llvm/unittests/CodeGen/MachineInstrTest.cpp +++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp @@ -6,6 +6,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineModuleInfo.h" @@ -273,6 +274,38 @@ TEST(MachineInstrPrintingTest, DebugLocPrinting) { StringRef(OS.str()).endswith("filename:1:5")); } +TEST(MachineInstrSpan, DistanceBegin) { + auto MF = createMachineFunction(); + auto MBB = MF->CreateMachineBasicBlock(); + + MCInstrDesc MCID = {0, 0, 0, 0, 0, 0, + 0, nullptr, nullptr, nullptr, 0, nullptr}; + + auto MII = MBB->begin(); + MachineInstrSpan MIS(MII, MBB); + ASSERT_TRUE(MIS.empty()); + + auto MI = MF->CreateMachineInstr(MCID, DebugLoc()); + MBB->insert(MII, MI); + ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1); +} + +TEST(MachineInstrSpan, DistanceEnd) { + auto MF = createMachineFunction(); + auto MBB = MF->CreateMachineBasicBlock(); + + MCInstrDesc MCID = {0, 0, 0, 0, 0, 0, + 0, nullptr, nullptr, nullptr, 0, nullptr}; + + auto MII = MBB->end(); + MachineInstrSpan MIS(MII, MBB); + ASSERT_TRUE(MIS.empty()); + + auto MI = MF->CreateMachineInstr(MCID, DebugLoc()); + MBB->insert(MII, MI); + ASSERT_TRUE(std::distance(MIS.begin(), MII) == 1); +} + static_assert(is_trivially_copyable<MCOperand>::value, "trivially copyable"); } // end namespace |