ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
//===- MachineInstrBundleIteratorTest.cpp ---------------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/MachineInstrBundleIterator.h"
|
2017-06-06 13:06:56 +02:00
|
|
|
#include "llvm/ADT/ilist_node.h"
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-09-11 18:38:18 +02:00
|
|
|
struct MyBundledInstr
|
|
|
|
: public ilist_node<MyBundledInstr, ilist_sentinel_tracking<true>> {
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
bool isBundledWithPred() const { return true; }
|
|
|
|
bool isBundledWithSucc() const { return true; }
|
|
|
|
};
|
|
|
|
typedef MachineInstrBundleIterator<MyBundledInstr> bundled_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyBundledInstr> const_bundled_iterator;
|
2016-09-11 20:51:28 +02:00
|
|
|
typedef MachineInstrBundleIterator<MyBundledInstr, true>
|
|
|
|
reverse_bundled_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyBundledInstr, true>
|
|
|
|
const_reverse_bundled_iterator;
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
|
|
|
|
#ifdef GTEST_HAS_DEATH_TEST
|
|
|
|
#ifndef NDEBUG
|
|
|
|
TEST(MachineInstrBundleIteratorTest, CheckForBundles) {
|
|
|
|
MyBundledInstr MBI;
|
2016-09-11 20:51:28 +02:00
|
|
|
auto I = MBI.getIterator();
|
|
|
|
auto RI = I.getReverse();
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
|
|
|
|
// 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.
|
2016-09-11 20:51:28 +02:00
|
|
|
EXPECT_DEATH((void)static_cast<bundled_iterator>(I),
|
|
|
|
"not legal to initialize");
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
EXPECT_DEATH((void)static_cast<bundled_iterator>(MBI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<bundled_iterator>(&MBI),
|
|
|
|
"not legal to initialize");
|
2016-09-11 20:51:28 +02:00
|
|
|
EXPECT_DEATH((void)static_cast<const_bundled_iterator>(I),
|
|
|
|
"not legal to initialize");
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
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");
|
2016-09-11 20:51:28 +02:00
|
|
|
EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(RI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(MBI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<reverse_bundled_iterator>(&MBI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(RI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(MBI),
|
|
|
|
"not legal to initialize");
|
|
|
|
EXPECT_DEATH((void)static_cast<const_reverse_bundled_iterator>(&MBI),
|
|
|
|
"not legal to initialize");
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
}
|
|
|
|
#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);
|
2016-09-11 19:12:28 +02:00
|
|
|
ASSERT_FALSE(MBI.getIterator() == I);
|
|
|
|
ASSERT_FALSE(CMBI.getIterator() == I);
|
|
|
|
ASSERT_FALSE(I == MBI.getIterator());
|
|
|
|
ASSERT_FALSE(I == CMBI.getIterator());
|
|
|
|
ASSERT_FALSE(MBI.getIterator() == CI);
|
|
|
|
ASSERT_FALSE(CMBI.getIterator() == CI);
|
|
|
|
ASSERT_FALSE(CI == MBI.getIterator());
|
|
|
|
ASSERT_FALSE(CI == CMBI.getIterator());
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
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);
|
2016-09-11 19:12:28 +02:00
|
|
|
ASSERT_TRUE(MBI.getIterator() != I);
|
|
|
|
ASSERT_TRUE(CMBI.getIterator() != I);
|
|
|
|
ASSERT_TRUE(I != MBI.getIterator());
|
|
|
|
ASSERT_TRUE(I != CMBI.getIterator());
|
|
|
|
ASSERT_TRUE(MBI.getIterator() != CI);
|
|
|
|
ASSERT_TRUE(CMBI.getIterator() != CI);
|
|
|
|
ASSERT_TRUE(CI != MBI.getIterator());
|
|
|
|
ASSERT_TRUE(CI != CMBI.getIterator());
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
}
|
|
|
|
|
2017-02-07 22:03:50 +01:00
|
|
|
struct MyUnbundledInstr
|
|
|
|
: ilist_node<MyUnbundledInstr, ilist_sentinel_tracking<true>> {
|
|
|
|
bool isBundledWithPred() const { return false; }
|
|
|
|
bool isBundledWithSucc() const { return false; }
|
|
|
|
};
|
|
|
|
typedef MachineInstrBundleIterator<MyUnbundledInstr> unbundled_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyUnbundledInstr>
|
|
|
|
const_unbundled_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<MyUnbundledInstr, true>
|
|
|
|
reverse_unbundled_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyUnbundledInstr, true>
|
|
|
|
const_reverse_unbundled_iterator;
|
|
|
|
|
|
|
|
TEST(MachineInstrBundleIteratorTest, ReverseConstructor) {
|
|
|
|
simple_ilist<MyUnbundledInstr, ilist_sentinel_tracking<true>> L;
|
|
|
|
const auto &CL = L;
|
|
|
|
MyUnbundledInstr A, B;
|
|
|
|
L.insert(L.end(), A);
|
|
|
|
L.insert(L.end(), B);
|
|
|
|
|
|
|
|
// Save typing.
|
|
|
|
typedef MachineInstrBundleIterator<MyUnbundledInstr> iterator;
|
|
|
|
typedef MachineInstrBundleIterator<MyUnbundledInstr, true> reverse_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyUnbundledInstr> const_iterator;
|
|
|
|
typedef MachineInstrBundleIterator<const MyUnbundledInstr, true>
|
|
|
|
const_reverse_iterator;
|
|
|
|
|
|
|
|
// Convert to bundle iterators.
|
|
|
|
auto begin = [&]() -> iterator { return L.begin(); };
|
|
|
|
auto end = [&]() -> iterator { return L.end(); };
|
|
|
|
auto rbegin = [&]() -> reverse_iterator { return L.rbegin(); };
|
|
|
|
auto rend = [&]() -> reverse_iterator { return L.rend(); };
|
|
|
|
auto cbegin = [&]() -> const_iterator { return CL.begin(); };
|
|
|
|
auto cend = [&]() -> const_iterator { return CL.end(); };
|
|
|
|
auto crbegin = [&]() -> const_reverse_iterator { return CL.rbegin(); };
|
|
|
|
auto crend = [&]() -> const_reverse_iterator { return CL.rend(); };
|
|
|
|
|
|
|
|
// Check conversion values.
|
|
|
|
EXPECT_EQ(begin(), iterator(rend()));
|
|
|
|
EXPECT_EQ(++begin(), iterator(++rbegin()));
|
|
|
|
EXPECT_EQ(end(), iterator(rbegin()));
|
|
|
|
EXPECT_EQ(rbegin(), reverse_iterator(end()));
|
|
|
|
EXPECT_EQ(++rbegin(), reverse_iterator(++begin()));
|
|
|
|
EXPECT_EQ(rend(), reverse_iterator(begin()));
|
|
|
|
|
|
|
|
// Check const iterator constructors.
|
|
|
|
EXPECT_EQ(cbegin(), const_iterator(rend()));
|
|
|
|
EXPECT_EQ(cbegin(), const_iterator(crend()));
|
|
|
|
EXPECT_EQ(crbegin(), const_reverse_iterator(end()));
|
|
|
|
EXPECT_EQ(crbegin(), const_reverse_iterator(cend()));
|
|
|
|
|
|
|
|
// Confirm lack of implicit conversions.
|
|
|
|
static_assert(!std::is_convertible<iterator, reverse_iterator>::value,
|
|
|
|
"unexpected implicit conversion");
|
|
|
|
static_assert(!std::is_convertible<reverse_iterator, iterator>::value,
|
|
|
|
"unexpected implicit conversion");
|
|
|
|
static_assert(
|
|
|
|
!std::is_convertible<const_iterator, const_reverse_iterator>::value,
|
|
|
|
"unexpected implicit conversion");
|
|
|
|
static_assert(
|
|
|
|
!std::is_convertible<const_reverse_iterator, const_iterator>::value,
|
|
|
|
"unexpected implicit conversion");
|
|
|
|
}
|
|
|
|
|
ADT: Remove all ilist_iterator => pointer casts, NFC
Remove all ilist_iterator to pointer casts. There were two reasons for
casts:
- Checking for an uninitialized (i.e., null) iterator. I added
MachineInstrBundleIterator::isValid() to check for that case.
- Comparing an iterator against the underlying pointer value while
avoiding converting the pointer value to an iterator. This is
occasionally necessary in MachineInstrBundleIterator, since there is
an assertion in the constructors that the underlying MachineInstr is
not bundled (but we don't care about that if we're just checking for
pointer equality).
To support the latter case, I rewrote the == and != operators for
ilist_iterator and MachineInstrBundleIterator.
- The implicit constructors now use enable_if to exclude
const-iterator => non-const-iterator conversions from overload
resolution (previously it was a compiler error on instantiation, now
it's SFINAE).
- The == and != operators are now global (friends), and are not
templated.
- MachineInstrBundleIterator has overloads to compare against both
const_pointer and const_reference. This avoids the implicit
conversions to MachineInstrBundleIterator that assert, instead just
checking the address (and I added unit tests to confirm this).
Notably, the only remaining uses of ilist_iterator::getNodePtrUnchecked
are in ilist.h, and no code outside of ilist*.h directly relies on this
UB end-iterator-to-pointer conversion anymore. It's still needed for
ilist_*sentinel_traits, but I'll clean that up soon.
llvm-svn: 278478
2016-08-12 07:05:36 +02:00
|
|
|
} // end namespace
|