xref: /llvm-project/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp (revision f197b1f78f854d8513ef617b8cfc61860f7b4b84)
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 : public ilist_node<MyBundledInstr> {
19   bool isBundledWithPred() const { return true; }
20   bool isBundledWithSucc() const { return true; }
21 };
22 typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator;
23 typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator;
24 
25 #ifdef GTEST_HAS_DEATH_TEST
26 #ifndef NDEBUG
27 TEST(MachineInstrBundleIteratorTest, CheckForBundles) {
28   MyBundledInstr MBI;
29 
30   // Confirm that MBI is always considered bundled.
31   EXPECT_TRUE(MBI.isBundledWithPred());
32   EXPECT_TRUE(MBI.isBundledWithSucc());
33 
34   // Confirm that iterators check in their constructor for bundled iterators.
35   EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI),
36                "not legal to initialize");
37   EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI),
38                "not legal to initialize");
39   EXPECT_DEATH((void)static_cast<const_bundled_iterator>(MBI),
40                "not legal to initialize");
41   EXPECT_DEATH((void)static_cast<const_bundled_iterator>(&MBI),
42                "not legal to initialize");
43 }
44 #endif
45 #endif
46 
47 TEST(MachineInstrBundleIteratorTest, CompareToBundledMI) {
48   MyBundledInstr MBI;
49   const MyBundledInstr &CMBI = MBI;
50   bundled_iterator I;
51   const_bundled_iterator CI;
52 
53   // Confirm that MBI is always considered bundled.
54   EXPECT_TRUE(MBI.isBundledWithPred());
55   EXPECT_TRUE(MBI.isBundledWithSucc());
56 
57   // These invocations will crash when !NDEBUG if a conversion is taking place.
58   // These checks confirm that comparison operators don't use any conversion
59   // operators.
60   ASSERT_FALSE(MBI == I);
61   ASSERT_FALSE(&MBI == I);
62   ASSERT_FALSE(CMBI == I);
63   ASSERT_FALSE(&CMBI == I);
64   ASSERT_FALSE(I == MBI);
65   ASSERT_FALSE(I == &MBI);
66   ASSERT_FALSE(I == CMBI);
67   ASSERT_FALSE(I == &CMBI);
68   ASSERT_FALSE(MBI == CI);
69   ASSERT_FALSE(&MBI == CI);
70   ASSERT_FALSE(CMBI == CI);
71   ASSERT_FALSE(&CMBI == CI);
72   ASSERT_FALSE(CI == MBI);
73   ASSERT_FALSE(CI == &MBI);
74   ASSERT_FALSE(CI == CMBI);
75   ASSERT_FALSE(CI == &CMBI);
76   ASSERT_TRUE(MBI != I);
77   ASSERT_TRUE(&MBI != I);
78   ASSERT_TRUE(CMBI != I);
79   ASSERT_TRUE(&CMBI != I);
80   ASSERT_TRUE(I != MBI);
81   ASSERT_TRUE(I != &MBI);
82   ASSERT_TRUE(I != CMBI);
83   ASSERT_TRUE(I != &CMBI);
84   ASSERT_TRUE(MBI != CI);
85   ASSERT_TRUE(&MBI != CI);
86   ASSERT_TRUE(CMBI != CI);
87   ASSERT_TRUE(&CMBI != CI);
88   ASSERT_TRUE(CI != MBI);
89   ASSERT_TRUE(CI != &MBI);
90   ASSERT_TRUE(CI != CMBI);
91   ASSERT_TRUE(CI != &CMBI);
92 }
93 
94 } // end namespace
95