summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/CodeGen/MachineInstrBundleIteratorTest.cpp
blob: 857994a3b29c96f0847ff09545dd6e07e71324d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===- MachineInstrBundleIteratorTest.cpp ---------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/ilist_node.h"
#include "llvm/CodeGen/MachineInstrBundleIterator.h"
#include "gtest/gtest.h"

using namespace llvm;

namespace {

struct MyBundledInstr : public ilist_node<MyBundledInstr> {
  bool isBundledWithPred() const { return true; }
  bool isBundledWithSucc() const { return true; }
};
typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator;
typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator;

#ifdef GTEST_HAS_DEATH_TEST
#ifndef NDEBUG
TEST(MachineInstrBundleIteratorTest, CheckForBundles) {
  MyBundledInstr MBI;

  // Confirm that MBI is always considered bundled.
  EXPECT_TRUE(MBI.isBundledWithPred());
  EXPECT_TRUE(MBI.isBundledWithSucc());

  // Confirm that iterators check in their constructor for bundled iterators.
  EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI),
               "not legal to initialize");
  EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI),
               "not legal to initialize");
  EXPECT_DEATH((void)static_cast<const_bundled_iterator>(MBI),
               "not legal to initialize");
  EXPECT_DEATH((void)static_cast<const_bundled_iterator>(&MBI),
               "not legal to initialize");
}
#endif
#endif

TEST(MachineInstrBundleIteratorTest, CompareToBundledMI) {
  MyBundledInstr MBI;
  const MyBundledInstr &CMBI = MBI;
  bundled_iterator I;
  const_bundled_iterator CI;

  // Confirm that MBI is always considered bundled.
  EXPECT_TRUE(MBI.isBundledWithPred());
  EXPECT_TRUE(MBI.isBundledWithSucc());

  // These invocations will crash when !NDEBUG if a conversion is taking place.
  // These checks confirm that comparison operators don't use any conversion
  // operators.
  ASSERT_FALSE(MBI == I);
  ASSERT_FALSE(&MBI == I);
  ASSERT_FALSE(CMBI == I);
  ASSERT_FALSE(&CMBI == I);
  ASSERT_FALSE(I == MBI);
  ASSERT_FALSE(I == &MBI);
  ASSERT_FALSE(I == CMBI);
  ASSERT_FALSE(I == &CMBI);
  ASSERT_FALSE(MBI == CI);
  ASSERT_FALSE(&MBI == CI);
  ASSERT_FALSE(CMBI == CI);
  ASSERT_FALSE(&CMBI == CI);
  ASSERT_FALSE(CI == MBI);
  ASSERT_FALSE(CI == &MBI);
  ASSERT_FALSE(CI == CMBI);
  ASSERT_FALSE(CI == &CMBI);
  ASSERT_TRUE(MBI != I);
  ASSERT_TRUE(&MBI != I);
  ASSERT_TRUE(CMBI != I);
  ASSERT_TRUE(&CMBI != I);
  ASSERT_TRUE(I != MBI);
  ASSERT_TRUE(I != &MBI);
  ASSERT_TRUE(I != CMBI);
  ASSERT_TRUE(I != &CMBI);
  ASSERT_TRUE(MBI != CI);
  ASSERT_TRUE(&MBI != CI);
  ASSERT_TRUE(CMBI != CI);
  ASSERT_TRUE(&CMBI != CI);
  ASSERT_TRUE(CI != MBI);
  ASSERT_TRUE(CI != &MBI);
  ASSERT_TRUE(CI != CMBI);
  ASSERT_TRUE(CI != &CMBI);
}

} // end namespace
OpenPOWER on IntegriCloud