blob: ca61fcbe59f030551f78e97288ef5344d789644c [file] [log] [blame]
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +00001//===- 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
14using namespace llvm;
15
16namespace {
17
Duncan P. N. Exon Smithcc9edac2016-09-11 16:38:18 +000018struct MyBundledInstr
19 : public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> {
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000020 bool isBundledWithPred() const { return true; }
21 bool isBundledWithSucc() const { return true; }
22};
23typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator;
24typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator;
25
26#ifdef GTEST_HAS_DEATH_TEST
27#ifndef NDEBUG
28TEST(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
48TEST(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);
Duncan P. N. Exon Smith3b22b182016-09-11 17:12:28 +000077 ASSERT_FALSE(MBI.getIterator() == I);
78 ASSERT_FALSE(CMBI.getIterator() == I);
79 ASSERT_FALSE(I == MBI.getIterator());
80 ASSERT_FALSE(I == CMBI.getIterator());
81 ASSERT_FALSE(MBI.getIterator() == CI);
82 ASSERT_FALSE(CMBI.getIterator() == CI);
83 ASSERT_FALSE(CI == MBI.getIterator());
84 ASSERT_FALSE(CI == CMBI.getIterator());
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +000085 ASSERT_TRUE(MBI != I);
86 ASSERT_TRUE(&MBI != I);
87 ASSERT_TRUE(CMBI != I);
88 ASSERT_TRUE(&CMBI != I);
89 ASSERT_TRUE(I != MBI);
90 ASSERT_TRUE(I != &MBI);
91 ASSERT_TRUE(I != CMBI);
92 ASSERT_TRUE(I != &CMBI);
93 ASSERT_TRUE(MBI != CI);
94 ASSERT_TRUE(&MBI != CI);
95 ASSERT_TRUE(CMBI != CI);
96 ASSERT_TRUE(&CMBI != CI);
97 ASSERT_TRUE(CI != MBI);
98 ASSERT_TRUE(CI != &MBI);
99 ASSERT_TRUE(CI != CMBI);
100 ASSERT_TRUE(CI != &CMBI);
Duncan P. N. Exon Smith3b22b182016-09-11 17:12:28 +0000101 ASSERT_TRUE(MBI.getIterator() != I);
102 ASSERT_TRUE(CMBI.getIterator() != I);
103 ASSERT_TRUE(I != MBI.getIterator());
104 ASSERT_TRUE(I != CMBI.getIterator());
105 ASSERT_TRUE(MBI.getIterator() != CI);
106 ASSERT_TRUE(CMBI.getIterator() != CI);
107 ASSERT_TRUE(CI != MBI.getIterator());
108 ASSERT_TRUE(CI != CMBI.getIterator());
Duncan P. N. Exon Smithf197b1f2016-08-12 05:05:36 +0000109}
110
111} // end namespace