diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2010-09-17 15:48:55 +0000 |
commit | d39c594d39df7f283c2fb8a704a3f31c501180d9 (patch) | |
tree | 36453626c792cccd91f783a38a169d610a6b9db9 /unittests | |
parent | 6144c1de6a7674dad94290650e4e14f24d42e421 (diff) | |
download | src-test2-d39c594d39df7f283c2fb8a704a3f31c501180d9.tar.gz src-test2-d39c594d39df7f283c2fb8a704a3f31c501180d9.zip |
Vendor import of llvm r114020 (from the release_28 branch):vendor/llvm/llvm-r114020
http://llvm.org/svn/llvm-project/llvm/branches/release_28@114020
Approved by: rpaulo (mentor)
Notes
Notes:
svn path=/vendor/llvm/dist/; revision=212793
svn path=/vendor/llvm/llvm-r114020/; revision=212794; tag=vendor/llvm/llvm-r114020
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/ADT/SmallVectorTest.cpp | 4 | ||||
-rw-r--r-- | unittests/ADT/StringRefTest.cpp | 9 | ||||
-rw-r--r-- | unittests/ADT/TripleTest.cpp | 117 | ||||
-rw-r--r-- | unittests/Analysis/Makefile | 15 | ||||
-rw-r--r-- | unittests/Analysis/ScalarEvolutionTest.cpp | 82 | ||||
-rw-r--r-- | unittests/ExecutionEngine/JIT/JITTest.cpp | 27 | ||||
-rw-r--r-- | unittests/Makefile | 2 | ||||
-rw-r--r-- | unittests/Makefile.unittest | 4 | ||||
-rw-r--r-- | unittests/Support/Casting.cpp | 154 | ||||
-rw-r--r-- | unittests/Support/ConstantRangeTest.cpp | 69 | ||||
-rw-r--r-- | unittests/Support/ValueHandleTest.cpp | 1 | ||||
-rw-r--r-- | unittests/VMCore/DerivedTypesTest.cpp | 57 | ||||
-rw-r--r-- | unittests/VMCore/InstructionsTest.cpp | 4 | ||||
-rw-r--r-- | unittests/VMCore/MetadataTest.cpp | 7 | ||||
-rw-r--r-- | unittests/VMCore/PassManagerTest.cpp | 12 |
15 files changed, 508 insertions, 56 deletions
diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index 991c7d6caac7..78dc393e5c18 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -13,6 +13,7 @@ #include "gtest/gtest.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Compiler.h" #include <stdarg.h> #include <list> @@ -76,7 +77,8 @@ public: return c0.getValue() == c1.getValue(); } - friend bool operator!=(const Constructable & c0, const Constructable & c1) { + friend bool ATTRIBUTE_UNUSED + operator!=(const Constructable & c0, const Constructable & c1) { return c0.getValue() != c1.getValue(); } }; diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 887ba5d1f9e6..7e4d0dcd413f 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -53,6 +53,14 @@ TEST(StringRefTest, StringOps) { EXPECT_EQ( 1, StringRef("aab").compare("aaa")); EXPECT_EQ(-1, StringRef("aab").compare("aabb")); EXPECT_EQ( 1, StringRef("aab").compare("aa")); + EXPECT_EQ( 1, StringRef("\xFF").compare("\1")); + + EXPECT_EQ(-1, StringRef("AaB").compare_lower("aAd")); + EXPECT_EQ( 0, StringRef("AaB").compare_lower("aab")); + EXPECT_EQ( 1, StringRef("AaB").compare_lower("AAA")); + EXPECT_EQ(-1, StringRef("AaB").compare_lower("aaBb")); + EXPECT_EQ( 1, StringRef("AaB").compare_lower("aA")); + EXPECT_EQ( 1, StringRef("\xFF").compare_lower("\1")); EXPECT_EQ(-1, StringRef("aab").compare_numeric("aad")); EXPECT_EQ( 0, StringRef("aab").compare_numeric("aab")); @@ -64,6 +72,7 @@ TEST(StringRefTest, StringOps) { EXPECT_EQ( 0, StringRef("10a").compare_numeric("10a")); EXPECT_EQ( 1, StringRef("2").compare_numeric("1")); EXPECT_EQ( 0, StringRef("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty")); + EXPECT_EQ( 1, StringRef("\xFF").compare_numeric("\1")); } TEST(StringRefTest, Operators) { diff --git a/unittests/ADT/TripleTest.cpp b/unittests/ADT/TripleTest.cpp index 1a9e81a0df74..067f5e5116cd 100644 --- a/unittests/ADT/TripleTest.cpp +++ b/unittests/ADT/TripleTest.cpp @@ -92,18 +92,117 @@ TEST(TripleTest, ParsedIDs) { T = Triple("huh"); EXPECT_EQ(Triple::UnknownArch, T.getArch()); +} - // Two exceptional cases. +static std::string Join(StringRef A, StringRef B, StringRef C) { + std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; + return Str; +} - T = Triple("i386-mingw32"); - EXPECT_EQ(Triple::x86, T.getArch()); - EXPECT_EQ(Triple::PC, T.getVendor()); - EXPECT_EQ(Triple::MinGW32, T.getOS()); +static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) { + std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; Str += '-'; + Str += D; return Str; +} - T = Triple("arm-elf"); - EXPECT_EQ(Triple::arm, T.getArch()); - EXPECT_EQ(Triple::UnknownVendor, T.getVendor()); - EXPECT_EQ(Triple::UnknownOS, T.getOS()); +TEST(TripleTest, Normalization) { + EXPECT_EQ("", Triple::normalize("")); + EXPECT_EQ("-", Triple::normalize("-")); + EXPECT_EQ("--", Triple::normalize("--")); + EXPECT_EQ("---", Triple::normalize("---")); + EXPECT_EQ("----", Triple::normalize("----")); + + EXPECT_EQ("a", Triple::normalize("a")); + EXPECT_EQ("a-b", Triple::normalize("a-b")); + EXPECT_EQ("a-b-c", Triple::normalize("a-b-c")); + EXPECT_EQ("a-b-c-d", Triple::normalize("a-b-c-d")); + + EXPECT_EQ("i386-b-c", Triple::normalize("i386-b-c")); + EXPECT_EQ("i386-a-c", Triple::normalize("a-i386-c")); + EXPECT_EQ("i386-a-b", Triple::normalize("a-b-i386")); + + EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c")); + EXPECT_EQ("-pc-b-c", Triple::normalize("pc-b-c")); + EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc")); + + EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux")); + EXPECT_EQ("--linux-b-c", Triple::normalize("linux-b-c")); + EXPECT_EQ("a--linux-c", Triple::normalize("a-linux-c")); + + EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386")); + EXPECT_EQ("i386-pc-", Triple::normalize("-pc-i386")); + EXPECT_EQ("-pc-linux-c", Triple::normalize("linux-pc-c")); + EXPECT_EQ("-pc-linux", Triple::normalize("linux-pc-")); + + EXPECT_EQ("i386", Triple::normalize("i386")); + EXPECT_EQ("-pc", Triple::normalize("pc")); + EXPECT_EQ("--linux", Triple::normalize("linux")); + + // Check that normalizing a permutated set of valid components returns a + // triple with the unpermuted components. + StringRef C[4]; + C[3] = "environment"; + for (int Arch = 1+Triple::UnknownArch; Arch < Triple::InvalidArch; ++Arch) { + C[0] = Triple::getArchTypeName(Triple::ArchType(Arch)); + for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC; + ++Vendor) { + C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor)); + for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) { + C[2] = Triple::getOSTypeName(Triple::OSType(OS)); + + std::string E = Join(C[0], C[1], C[2]); + std::string F = Join(C[0], C[1], C[2], C[3]); + EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3]))); + + // If a value has multiple interpretations, then the permutation + // test will inevitably fail. Currently this is only the case for + // "psp" which parses as both an architecture and an O/S. + if (OS == Triple::Psp) + continue; + + EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1]))); + EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0]))); + EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2]))); + EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1]))); + EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0]))); + + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3]))); + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3]))); + EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0]))); + EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1]))); + EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0]))); + } + } + } + + EXPECT_EQ("a-b-psp", Triple::normalize("a-b-psp")); + EXPECT_EQ("psp-b-c", Triple::normalize("psp-b-c")); + + // Various real-world funky triples. The value returned by GCC's config.sub + // is given in the comment. + EXPECT_EQ("i386--mingw32", Triple::normalize("i386-mingw32")); // i386-pc-mingw32 + EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu + EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu + EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu + EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu } TEST(TripleTest, MutateName) { diff --git a/unittests/Analysis/Makefile b/unittests/Analysis/Makefile new file mode 100644 index 000000000000..f89240ec7042 --- /dev/null +++ b/unittests/Analysis/Makefile @@ -0,0 +1,15 @@ +##===- unittests/Analysis/Makefile -------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL = ../.. +TESTNAME = Analysis +LINK_COMPONENTS := core support target analysis ipa + +include $(LEVEL)/Makefile.config +include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp new file mode 100644 index 000000000000..b7341603cf69 --- /dev/null +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -0,0 +1,82 @@ +//===- ScalarEvolutionsTest.cpp - ScalarEvolution unit tests --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <llvm/Analysis/ScalarEvolutionExpressions.h> +#include <llvm/GlobalVariable.h> +#include <llvm/Constants.h> +#include <llvm/LLVMContext.h> +#include <llvm/Module.h> +#include <llvm/PassManager.h> +#include "gtest/gtest.h" + +namespace llvm { +namespace { + +TEST(ScalarEvolutionsTest, SCEVUnknownRAUW) { + LLVMContext Context; + Module M("world", Context); + + const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), + std::vector<const Type *>(), false); + Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + BasicBlock *BB = BasicBlock::Create(Context, "entry", F); + ReturnInst::Create(Context, 0, BB); + + const Type *Ty = Type::getInt1Ty(Context); + Constant *Init = Constant::getNullValue(Ty); + Value *V0 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V0"); + Value *V1 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V1"); + Value *V2 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V2"); + + // Create a ScalarEvolution and "run" it so that it gets initialized. + PassManager PM; + ScalarEvolution &SE = *new ScalarEvolution(); + PM.add(&SE); + PM.run(M); + + const SCEV *S0 = SE.getSCEV(V0); + const SCEV *S1 = SE.getSCEV(V1); + const SCEV *S2 = SE.getSCEV(V2); + + const SCEV *P0 = SE.getAddExpr(S0, S0); + const SCEV *P1 = SE.getAddExpr(S1, S1); + const SCEV *P2 = SE.getAddExpr(S2, S2); + + const SCEVMulExpr *M0 = cast<SCEVMulExpr>(P0); + const SCEVMulExpr *M1 = cast<SCEVMulExpr>(P1); + const SCEVMulExpr *M2 = cast<SCEVMulExpr>(P2); + + EXPECT_EQ(cast<SCEVConstant>(M0->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast<SCEVConstant>(M1->getOperand(0))->getValue()->getZExtValue(), + 2u); + EXPECT_EQ(cast<SCEVConstant>(M2->getOperand(0))->getValue()->getZExtValue(), + 2u); + + // Before the RAUWs, these are all pointing to separate values. + EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V1); + EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V2); + + // Do some RAUWs. + V2->replaceAllUsesWith(V1); + V1->replaceAllUsesWith(V0); + + // After the RAUWs, these should all be pointing to V0. + EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V0); + EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V0); + + // Manually clean up, since we allocated new SCEV objects after the + // pass was finished. + SE.releaseMemory(); +} + +} // end anonymous namespace +} // end namespace llvm diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 8f0582d3e8de..ceacbbe62a45 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -65,8 +65,6 @@ public: stubsAllocated = 0; } - void setSizeRequired(bool Required) { SizeRequired = Required; } - virtual void setMemoryWritable() { Base->setMemoryWritable(); } virtual void setMemoryExecutable() { Base->setMemoryExecutable(); } virtual void setPoisonMemory(bool poison) { Base->setPoisonMemory(poison); } @@ -630,31 +628,6 @@ TEST_F(JITTest, AvailableExternallyFunctionIsntCompiled) { << " not 7 from the IR version."; } -TEST_F(JITTest, NeedsExactSizeWithManyGlobals) { - // PR5291: When the JMM needed the exact size of function bodies before - // starting to emit them, the JITEmitter would modify a set while iterating - // over it. - TheJIT->DisableLazyCompilation(true); - RJMM->setSizeRequired(true); - - LoadAssembly("@A = global i32 42 " - "@B = global i32* @A " - "@C = global i32** @B " - "@D = global i32*** @C " - "@E = global i32**** @D " - "@F = global i32***** @E " - "@G = global i32****** @F " - "@H = global i32******* @G " - "@I = global i32******** @H " - "define i32********* @test() { " - " ret i32********* @I " - "}"); - Function *testIR = M->getFunction("test"); - int32_t********* (*test)() = reinterpret_cast<int32_t*********(*)()>( - (intptr_t)TheJIT->getPointerToFunction(testIR)); - EXPECT_EQ(42, *********test()); -} - TEST_F(JITTest, EscapedLazyStubStillCallable) { TheJIT->DisableLazyCompilation(false); LoadAssembly("define internal i32 @stubbed() { " diff --git a/unittests/Makefile b/unittests/Makefile index 9f377cd744c1..0401cd1c673a 100644 --- a/unittests/Makefile +++ b/unittests/Makefile @@ -9,7 +9,7 @@ LEVEL = .. -PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore +PARALLEL_DIRS = ADT ExecutionEngine Support Transforms VMCore Analysis include $(LEVEL)/Makefile.common diff --git a/unittests/Makefile.unittest b/unittests/Makefile.unittest index 2a701a019d8b..9a75b2c2eb8f 100644 --- a/unittests/Makefile.unittest +++ b/unittests/Makefile.unittest @@ -37,10 +37,10 @@ TESTLIBS = -lGoogleTest -lUnitTestMain ifeq ($(ENABLE_SHARED), 1) # Add the absolute path to the dynamic library. This is ok because # we'll never install unittests. - LD.Flags += $(RPATH) -Wl,$(LibDir) + LD.Flags += $(RPATH) -Wl,$(SharedLibDir) # Also set {DYLD,LD}_LIBRARY_PATH because OSX ignores the rpath most # of the time. - Run.Shared := $(SHLIBPATH_VAR)="$(LibDir)$${$(SHLIBPATH_VAR):+:}$$$(SHLIBPATH_VAR)" + Run.Shared := $(SHLIBPATH_VAR)="$(SharedLibDir)$${$(SHLIBPATH_VAR):+:}$$$(SHLIBPATH_VAR)" endif $(LLVMUnitTestExe): $(ObjectsO) $(ProjLibsPaths) $(LLVMLibsPaths) diff --git a/unittests/Support/Casting.cpp b/unittests/Support/Casting.cpp new file mode 100644 index 000000000000..ae84693bd636 --- /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 6b8d01d553f4..091ecd4aadeb 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 6a6528fbddfb..ba610ea4ff9a 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) {} }; diff --git a/unittests/VMCore/DerivedTypesTest.cpp b/unittests/VMCore/DerivedTypesTest.cpp index 2e0450d6e5ce..9dea6ff2a904 100644 --- a/unittests/VMCore/DerivedTypesTest.cpp +++ b/unittests/VMCore/DerivedTypesTest.cpp @@ -9,13 +9,66 @@ #include "gtest/gtest.h" #include "../lib/VMCore/LLVMContextImpl.h" -#include "llvm/Type.h" #include "llvm/DerivedTypes.h" #include "llvm/LLVMContext.h" +#include "llvm/Constants.h" +#include "llvm/Support/ValueHandle.h" using namespace llvm; namespace { +static void PR7658() { + LLVMContext ctx; + + WeakVH NullPtr; + PATypeHolder h1; + { + OpaqueType *o1 = OpaqueType::get(ctx); + PointerType *p1 = PointerType::get(o1, 0); + + std::vector<const Type *> t1; + t1.push_back(IntegerType::get(ctx, 32)); + t1.push_back(p1); + NullPtr = ConstantPointerNull::get(p1); + OpaqueType *o2 = OpaqueType::get (ctx); + PointerType *p2 = PointerType::get (o2, 0); + t1.push_back(p2); + + + StructType *s1 = StructType::get(ctx, t1); + h1 = s1; + o1->refineAbstractTypeTo(s1); + o2->refineAbstractTypeTo(h1.get()); // h1 = { i32, \2*, \2* } + } + + + OpaqueType *o3 = OpaqueType::get(ctx); + PointerType *p3 = PointerType::get(o3, 0); // p3 = opaque* + + std::vector<const Type *> t2; + t2.push_back(IntegerType::get(ctx, 32)); + t2.push_back(p3); + + std::vector<Constant *> v2; + v2.push_back(ConstantInt::get(IntegerType::get(ctx, 32), 14)); + v2.push_back(ConstantPointerNull::get(p3)); + + OpaqueType *o4 = OpaqueType::get(ctx); + { + PointerType *p4 = PointerType::get(o4, 0); + t2.push_back(p4); + v2.push_back(ConstantPointerNull::get(p4)); + } + + WeakVH CS = ConstantStruct::get(ctx, v2, false); // { i32 14, opaque* null, opaque* null} + + StructType *s2 = StructType::get(ctx, t2); + PATypeHolder h2(s2); + o3->refineAbstractTypeTo(s2); + o4->refineAbstractTypeTo(h2.get()); +} + + TEST(OpaqueTypeTest, RegisterWithContext) { LLVMContext C; LLVMContextImpl *pImpl = C.pImpl; @@ -28,6 +81,8 @@ TEST(OpaqueTypeTest, RegisterWithContext) { EXPECT_EQ(2u, pImpl->OpaqueTypes.size()); } EXPECT_EQ(1u, pImpl->OpaqueTypes.size()); + + PR7658(); } } // namespace diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp index c1baa74487aa..c9fe2a13166f 100644 --- a/unittests/VMCore/InstructionsTest.cpp +++ b/unittests/VMCore/InstructionsTest.cpp @@ -59,9 +59,9 @@ TEST(InstructionsTest, BranchInst) { EXPECT_EQ(b0->getNumOperands(), 1U); EXPECT_NE(b0->op_begin(), b0->op_end()); - EXPECT_EQ(next(b0->op_begin()), b0->op_end()); + EXPECT_EQ(llvm::next(b0->op_begin()), b0->op_end()); - EXPECT_EQ(next(b0->op_begin()), b0->op_end()); + EXPECT_EQ(llvm::next(b0->op_begin()), b0->op_end()); const IntegerType* Int1 = IntegerType::get(C, 1); Constant* One = ConstantInt::get(Int1, 1, true); diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp index 04db486cd871..942b84823250 100644 --- a/unittests/VMCore/MetadataTest.cpp +++ b/unittests/VMCore/MetadataTest.cpp @@ -130,11 +130,12 @@ TEST(NamedMDNodeTest, Search) { MDNode *n = MDNode::get(Context, &V, 1); MDNode *n2 = MDNode::get(Context, &V2, 1); - MDNode *Nodes[2] = { n, n2 }; - Module M("MyModule", Context); const char *Name = "llvm.NMD1"; - NamedMDNode *NMD = NamedMDNode::Create(Context, Name, &Nodes[0], 2, &M); + NamedMDNode *NMD = M.getOrInsertNamedMetadata(Name); + NMD->addOperand(n); + NMD->addOperand(n2); + std::string Str; raw_string_ostream oss(Str); NMD->print(oss); diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp index cabfc44602cf..96ee5b458960 100644 --- a/unittests/VMCore/PassManagerTest.cpp +++ b/unittests/VMCore/PassManagerTest.cpp @@ -40,7 +40,7 @@ namespace llvm { public: static char run; static char ID; - ModuleNDNM() : ModulePass(&ID) {} + ModuleNDNM() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { run++; return false; @@ -56,7 +56,7 @@ namespace llvm { public: static char run; static char ID; - ModuleNDM() : ModulePass(&ID) {} + ModuleNDM() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { run++; return true; @@ -70,7 +70,7 @@ namespace llvm { public: static char run; static char ID; - ModuleNDM2() : ModulePass(&ID) {} + ModuleNDM2() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { run++; return true; @@ -83,7 +83,7 @@ namespace llvm { public: static char run; static char ID; - ModuleDNM() : ModulePass(&ID) {} + ModuleDNM() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); run++; @@ -119,7 +119,7 @@ namespace llvm { EXPECT_TRUE(finalized); EXPECT_EQ(run, runc); } - PassTestBase() : P(&ID), allocated(0) { + PassTestBase() : P(ID), allocated(0) { initialized = false; finalized = false; runc = 0; @@ -253,7 +253,7 @@ namespace llvm { struct OnTheFlyTest: public ModulePass { public: static char ID; - OnTheFlyTest() : ModulePass(&ID) {} + OnTheFlyTest() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) { |