diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
commit | 5d5cc59cc77afe655b3707cb0e69e0827b444cad (patch) | |
tree | 36453626c792cccd91f783a38a169d610a6b9db9 /unittests/Support | |
parent | 786a18553586229ad99ecb5ecde8a9d914c45e27 (diff) | |
download | FreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.zip FreeBSD-src-5d5cc59cc77afe655b3707cb0e69e0827b444cad.tar.gz |
Vendor import of llvm r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/llvm/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'unittests/Support')
-rw-r--r-- | unittests/Support/Casting.cpp | 154 | ||||
-rw-r--r-- | unittests/Support/ConstantRangeTest.cpp | 69 | ||||
-rw-r--r-- | unittests/Support/ValueHandleTest.cpp | 1 |
3 files changed, 220 insertions, 4 deletions
diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp new file mode 100644 index 0000000..ae84693 --- /dev/null +++ b/unittests/Support/Casting.cpp @@ -0,0 +1,154 @@ +//===---------- llvm/unittest/Support/Casting.cpp - Casting tests ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/Casting.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" + +#include "gtest/gtest.h" +#include <cstdlib> + +namespace llvm { + +// set up two example classes +// with conversion facility +// +struct bar { + bar() {} + struct foo *baz(); + struct foo *caz(); + struct foo *daz(); + struct foo *naz(); +private: + bar(const bar &); +}; +struct foo { + void ext() const; + /* static bool classof(const bar *X) { + cerr << "Classof: " << X << "\n"; + return true; + }*/ +}; + +template <> struct isa_impl<foo, bar> { + static inline bool doit(const bar &Val) { + dbgs() << "Classof: " << &Val << "\n"; + return true; + } +}; + +foo *bar::baz() { + return cast<foo>(this); +} + +foo *bar::caz() { + return cast_or_null<foo>(this); +} + +foo *bar::daz() { + return dyn_cast<foo>(this); +} + +foo *bar::naz() { + return dyn_cast_or_null<foo>(this); +} + + +bar *fub(); +} // End llvm namespace + +using namespace llvm; + +namespace { + +const foo *null_foo = NULL; + +extern bar &B1; +extern const bar *B2; +// test various configurations of const +const bar &B3 = B1; +const bar *const B4 = B2; + +TEST(CastingTest, isa) { + EXPECT_TRUE(isa<foo>(B1)); + EXPECT_TRUE(isa<foo>(B2)); + EXPECT_TRUE(isa<foo>(B3)); + EXPECT_TRUE(isa<foo>(B4)); +} + +TEST(CastingTest, cast) { + foo &F1 = cast<foo>(B1); + EXPECT_NE(&F1, null_foo); + const foo *F3 = cast<foo>(B2); + EXPECT_NE(F3, null_foo); + const foo *F4 = cast<foo>(B2); + EXPECT_NE(F4, null_foo); + const foo &F5 = cast<foo>(B3); + EXPECT_NE(&F5, null_foo); + const foo *F6 = cast<foo>(B4); + EXPECT_NE(F6, null_foo); + foo *F7 = cast<foo>(fub()); + EXPECT_EQ(F7, null_foo); + foo *F8 = B1.baz(); + EXPECT_NE(F8, null_foo); +} + +TEST(CastingTest, cast_or_null) { + const foo *F11 = cast_or_null<foo>(B2); + EXPECT_NE(F11, null_foo); + const foo *F12 = cast_or_null<foo>(B2); + EXPECT_NE(F12, null_foo); + const foo *F13 = cast_or_null<foo>(B4); + EXPECT_NE(F13, null_foo); + const foo *F14 = cast_or_null<foo>(fub()); // Shouldn't print. + EXPECT_EQ(F14, null_foo); + foo *F15 = B1.caz(); + EXPECT_NE(F15, null_foo); +} + +TEST(CastingTest, dyn_cast) { + const foo *F1 = dyn_cast<foo>(B2); + EXPECT_NE(F1, null_foo); + const foo *F2 = dyn_cast<foo>(B2); + EXPECT_NE(F2, null_foo); + const foo *F3 = dyn_cast<foo>(B4); + EXPECT_NE(F3, null_foo); + // foo *F4 = dyn_cast<foo>(fub()); // not permittible + // EXPECT_EQ(F4, null_foo); + foo *F5 = B1.daz(); + EXPECT_NE(F5, null_foo); +} + +TEST(CastingTest, dyn_cast_or_null) { + const foo *F1 = dyn_cast_or_null<foo>(B2); + EXPECT_NE(F1, null_foo); + const foo *F2 = dyn_cast_or_null<foo>(B2); + EXPECT_NE(F2, null_foo); + const foo *F3 = dyn_cast_or_null<foo>(B4); + EXPECT_NE(F3, null_foo); + foo *F4 = dyn_cast_or_null<foo>(fub()); + EXPECT_EQ(F4, null_foo); + foo *F5 = B1.naz(); + EXPECT_NE(F5, null_foo); +} + +// These lines are errors... +//foo *F20 = cast<foo>(B2); // Yields const foo* +//foo &F21 = cast<foo>(B3); // Yields const foo& +//foo *F22 = cast<foo>(B4); // Yields const foo* +//foo &F23 = cast_or_null<foo>(B1); +//const foo &F24 = cast_or_null<foo>(B3); + + +bar B; +bar &B1 = B; +const bar *B2 = &B; +} // anonymous namespace + +bar *llvm::fub() { return 0; } diff --git a/unittests/Support/ConstantRangeTest.cpp b/unittests/Support/ConstantRangeTest.cpp index 6b8d01d..091ecd4a 100644 --- a/unittests/Support/ConstantRangeTest.cpp +++ b/unittests/Support/ConstantRangeTest.cpp @@ -33,6 +33,7 @@ ConstantRange ConstantRangeTest::Wrap(APInt(16, 0xaaa), APInt(16, 0xa)); TEST_F(ConstantRangeTest, Basics) { EXPECT_TRUE(Full.isFullSet()); EXPECT_FALSE(Full.isEmptySet()); + EXPECT_TRUE(Full.inverse().isEmptySet()); EXPECT_FALSE(Full.isWrappedSet()); EXPECT_TRUE(Full.contains(APInt(16, 0x0))); EXPECT_TRUE(Full.contains(APInt(16, 0x9))); @@ -42,6 +43,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_FALSE(Empty.isFullSet()); EXPECT_TRUE(Empty.isEmptySet()); + EXPECT_TRUE(Empty.inverse().isFullSet()); EXPECT_FALSE(Empty.isWrappedSet()); EXPECT_FALSE(Empty.contains(APInt(16, 0x0))); EXPECT_FALSE(Empty.contains(APInt(16, 0x9))); @@ -57,6 +59,7 @@ TEST_F(ConstantRangeTest, Basics) { EXPECT_TRUE(One.contains(APInt(16, 0xa))); EXPECT_FALSE(One.contains(APInt(16, 0xaa9))); EXPECT_FALSE(One.contains(APInt(16, 0xaaa))); + EXPECT_FALSE(One.inverse().contains(APInt(16, 0xa))); EXPECT_FALSE(Some.isFullSet()); EXPECT_FALSE(Some.isEmptySet()); @@ -256,11 +259,31 @@ TEST_F(ConstantRangeTest, Add) { EXPECT_EQ(Empty.add(Wrap), Empty); EXPECT_EQ(Empty.add(APInt(16, 4)), Empty); EXPECT_EQ(Some.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xe), APInt(16, 0xaae))); + ConstantRange(APInt(16, 0xe), APInt(16, 0xaae))); EXPECT_EQ(Wrap.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xaae), APInt(16, 0xe))); + ConstantRange(APInt(16, 0xaae), APInt(16, 0xe))); EXPECT_EQ(One.add(APInt(16, 4)), - ConstantRange(APInt(16, 0xe))); + ConstantRange(APInt(16, 0xe))); +} + +TEST_F(ConstantRangeTest, Sub) { + EXPECT_EQ(Full.sub(APInt(16, 4)), Full); + EXPECT_EQ(Full.sub(Full), Full); + EXPECT_EQ(Full.sub(Empty), Empty); + EXPECT_EQ(Full.sub(One), Full); + EXPECT_EQ(Full.sub(Some), Full); + EXPECT_EQ(Full.sub(Wrap), Full); + EXPECT_EQ(Empty.sub(Empty), Empty); + EXPECT_EQ(Empty.sub(One), Empty); + EXPECT_EQ(Empty.sub(Some), Empty); + EXPECT_EQ(Empty.sub(Wrap), Empty); + EXPECT_EQ(Empty.sub(APInt(16, 4)), Empty); + EXPECT_EQ(Some.sub(APInt(16, 4)), + ConstantRange(APInt(16, 0x6), APInt(16, 0xaa6))); + EXPECT_EQ(Wrap.sub(APInt(16, 4)), + ConstantRange(APInt(16, 0xaa6), APInt(16, 0x6))); + EXPECT_EQ(One.sub(APInt(16, 4)), + ConstantRange(APInt(16, 0x6))); } TEST_F(ConstantRangeTest, Multiply) { @@ -348,4 +371,44 @@ TEST_F(ConstantRangeTest, UDiv) { EXPECT_EQ(Wrap.udiv(Wrap), Full); } +TEST_F(ConstantRangeTest, Shl) { + EXPECT_EQ(Full.shl(Full), Full); + EXPECT_EQ(Full.shl(Empty), Empty); + EXPECT_EQ(Full.shl(One), Full); // TODO: [0, (-1 << 0xa) + 1) + EXPECT_EQ(Full.shl(Some), Full); // TODO: [0, (-1 << 0xa) + 1) + EXPECT_EQ(Full.shl(Wrap), Full); + EXPECT_EQ(Empty.shl(Empty), Empty); + EXPECT_EQ(Empty.shl(One), Empty); + EXPECT_EQ(Empty.shl(Some), Empty); + EXPECT_EQ(Empty.shl(Wrap), Empty); + EXPECT_EQ(One.shl(One), ConstantRange(APInt(16, 0xa << 0xa), + APInt(16, (0xa << 0xa) + 1))); + EXPECT_EQ(One.shl(Some), Full); // TODO: [0xa << 0xa, 0) + EXPECT_EQ(One.shl(Wrap), Full); // TODO: [0xa, 0xa << 14 + 1) + EXPECT_EQ(Some.shl(Some), Full); // TODO: [0xa << 0xa, 0xfc01) + EXPECT_EQ(Some.shl(Wrap), Full); // TODO: [0xa, 0x7ff << 0x5 + 1) + EXPECT_EQ(Wrap.shl(Wrap), Full); +} + +TEST_F(ConstantRangeTest, Lshr) { + EXPECT_EQ(Full.lshr(Full), Full); + EXPECT_EQ(Full.lshr(Empty), Empty); + EXPECT_EQ(Full.lshr(One), ConstantRange(APInt(16, 0), + APInt(16, (0xffff >> 0xa) + 1))); + EXPECT_EQ(Full.lshr(Some), ConstantRange(APInt(16, 0), + APInt(16, (0xffff >> 0xa) + 1))); + EXPECT_EQ(Full.lshr(Wrap), Full); + EXPECT_EQ(Empty.lshr(Empty), Empty); + EXPECT_EQ(Empty.lshr(One), Empty); + EXPECT_EQ(Empty.lshr(Some), Empty); + EXPECT_EQ(Empty.lshr(Wrap), Empty); + EXPECT_EQ(One.lshr(One), ConstantRange(APInt(16, 0))); + EXPECT_EQ(One.lshr(Some), ConstantRange(APInt(16, 0))); + EXPECT_EQ(One.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xb))); + EXPECT_EQ(Some.lshr(Some), ConstantRange(APInt(16, 0), + APInt(16, (0xaaa >> 0xa) + 1))); + EXPECT_EQ(Some.lshr(Wrap), ConstantRange(APInt(16, 0), APInt(16, 0xaaa))); + EXPECT_EQ(Wrap.lshr(Wrap), Full); +} + } // anonymous namespace diff --git a/unittests/Support/ValueHandleTest.cpp b/unittests/Support/ValueHandleTest.cpp index 6a6528f..ba610ea 100644 --- a/unittests/Support/ValueHandleTest.cpp +++ b/unittests/Support/ValueHandleTest.cpp @@ -35,7 +35,6 @@ protected: class ConcreteCallbackVH : public CallbackVH { public: - ConcreteCallbackVH() : CallbackVH() {} ConcreteCallbackVH(Value *V) : CallbackVH(V) {} }; |