1 //===- MachineInstrBundleIteratorTest.cpp ---------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/ADT/ilist_node.h" 11 #include "llvm/CodeGen/MachineInstrBundleIterator.h" 12 #include "gtest/gtest.h" 13 14 using namespace llvm; 15 16 namespace { 17 18 struct MyBundledInstr 19 : public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> { 20 bool isBundledWithPred() const { return true; } 21 bool isBundledWithSucc() const { return true; } 22 }; 23 typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator; 24 typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator; 25 26 #ifdef GTEST_HAS_DEATH_TEST 27 #ifndef NDEBUG 28 TEST(MachineInstrBundleIteratorTest, CheckForBundles) { 29 MyBundledInstr MBI; 30 31 // Confirm that MBI is always considered bundled. 32 EXPECT_TRUE(MBI.isBundledWithPred()); 33 EXPECT_TRUE(MBI.isBundledWithSucc()); 34 35 // Confirm that iterators check in their constructor for bundled iterators. 36 EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI), 37 "not legal to initialize"); 38 EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI), 39 "not legal to initialize"); 40 EXPECT_DEATH((void)static_cast<const_bundled_iterator>(MBI), 41 "not legal to initialize"); 42 EXPECT_DEATH((void)static_cast<const_bundled_iterator>(&MBI), 43 "not legal to initialize"); 44 } 45 #endif 46 #endif 47 48 TEST(MachineInstrBundleIteratorTest, CompareToBundledMI) { 49 MyBundledInstr MBI; 50 const MyBundledInstr &CMBI = MBI; 51 bundled_iterator I; 52 const_bundled_iterator CI; 53 54 // Confirm that MBI is always considered bundled. 55 EXPECT_TRUE(MBI.isBundledWithPred()); 56 EXPECT_TRUE(MBI.isBundledWithSucc()); 57 58 // These invocations will crash when !NDEBUG if a conversion is taking place. 59 // These checks confirm that comparison operators don't use any conversion 60 // operators. 61 ASSERT_FALSE(MBI == I); 62 ASSERT_FALSE(&MBI == I); 63 ASSERT_FALSE(CMBI == I); 64 ASSERT_FALSE(&CMBI == I); 65 ASSERT_FALSE(I == MBI); 66 ASSERT_FALSE(I == &MBI); 67 ASSERT_FALSE(I == CMBI); 68 ASSERT_FALSE(I == &CMBI); 69 ASSERT_FALSE(MBI == CI); 70 ASSERT_FALSE(&MBI == CI); 71 ASSERT_FALSE(CMBI == CI); 72 ASSERT_FALSE(&CMBI == CI); 73 ASSERT_FALSE(CI == MBI); 74 ASSERT_FALSE(CI == &MBI); 75 ASSERT_FALSE(CI == CMBI); 76 ASSERT_FALSE(CI == &CMBI); 77 ASSERT_TRUE(MBI != I); 78 ASSERT_TRUE(&MBI != I); 79 ASSERT_TRUE(CMBI != I); 80 ASSERT_TRUE(&CMBI != I); 81 ASSERT_TRUE(I != MBI); 82 ASSERT_TRUE(I != &MBI); 83 ASSERT_TRUE(I != CMBI); 84 ASSERT_TRUE(I != &CMBI); 85 ASSERT_TRUE(MBI != CI); 86 ASSERT_TRUE(&MBI != CI); 87 ASSERT_TRUE(CMBI != CI); 88 ASSERT_TRUE(&CMBI != CI); 89 ASSERT_TRUE(CI != MBI); 90 ASSERT_TRUE(CI != &MBI); 91 ASSERT_TRUE(CI != CMBI); 92 ASSERT_TRUE(CI != &CMBI); 93 } 94 95 } // end namespace 96