diff options
author | Stephen Hines <srhines@google.com> | 2014-05-29 02:49:00 -0700 |
---|---|---|
committer | Stephen Hines <srhines@google.com> | 2014-05-29 02:49:00 -0700 |
commit | dce4a407a24b04eebc6a376f8e62b41aaa7b071f (patch) | |
tree | dcebc53f2b182f145a2e659393bf9a0472cedf23 /unittests/IR | |
parent | 220b921aed042f9e520c26cffd8282a94c66c3d5 (diff) | |
download | external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.zip external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.gz external_llvm-dce4a407a24b04eebc6a376f8e62b41aaa7b071f.tar.bz2 |
Update LLVM for 3.5 rebase (r209712).
Change-Id: I149556c940fb7dc92d075273c87ff584f400941f
Diffstat (limited to 'unittests/IR')
-rw-r--r-- | unittests/IR/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittests/IR/ConstantsTest.cpp | 28 | ||||
-rw-r--r-- | unittests/IR/InstructionsTest.cpp | 33 | ||||
-rw-r--r-- | unittests/IR/MDBuilderTest.cpp | 1 | ||||
-rw-r--r-- | unittests/IR/UserTest.cpp | 96 | ||||
-rw-r--r-- | unittests/IR/VerifierTest.cpp | 4 |
6 files changed, 160 insertions, 3 deletions
diff --git a/unittests/IR/CMakeLists.txt b/unittests/IR/CMakeLists.txt index 7368a24..b439d59 100644 --- a/unittests/IR/CMakeLists.txt +++ b/unittests/IR/CMakeLists.txt @@ -21,6 +21,7 @@ set(IRSources PatternMatch.cpp TypeBuilderTest.cpp TypesTest.cpp + UserTest.cpp ValueHandleTest.cpp ValueMapTest.cpp ValueTest.cpp diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp index b3aa810..c11729c 100644 --- a/unittests/IR/ConstantsTest.cpp +++ b/unittests/IR/ConstantsTest.cpp @@ -254,6 +254,34 @@ TEST(ConstantsTest, AsInstructionsTest) { P6STR ", i32 1"); } +#ifdef GTEST_HAS_DEATH_TEST +#ifndef NDEBUG +TEST(ConstantsTest, ReplaceWithConstantTest) { + std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext())); + + Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); + Constant *One = ConstantInt::get(Int32Ty, 1); + + Constant *Global = + M->getOrInsertGlobal("dummy", PointerType::getUnqual(Int32Ty)); + Constant *GEP = ConstantExpr::getGetElementPtr(Global, One); + EXPECT_DEATH(Global->replaceAllUsesWith(GEP), + "this->replaceAllUsesWith\\(expr\\(this\\)\\) is NOT valid!"); +} + +TEST(ConstantsTest, ReplaceInAliasTest) { + std::unique_ptr<Module> M(new Module("MyModule", getGlobalContext())); + + Type *Int32Ty = Type::getInt32Ty(getGlobalContext()); + auto *Global = cast<GlobalObject>(M->getOrInsertGlobal("dummy", Int32Ty)); + auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "alias", Global); + EXPECT_DEATH(Global->replaceAllUsesWith(GA), + "replaceAliasUseWith cannot form an alias cycle"); +} + +#endif +#endif + #undef CHECK } // end anonymous namespace diff --git a/unittests/IR/InstructionsTest.cpp b/unittests/IR/InstructionsTest.cpp index e76afa8..336f5a2 100644 --- a/unittests/IR/InstructionsTest.cpp +++ b/unittests/IR/InstructionsTest.cpp @@ -483,6 +483,39 @@ TEST(InstructionsTest, isEliminableCastPair) { } +TEST(InstructionsTest, CloneCall) { + LLVMContext &C(getGlobalContext()); + Type *Int32Ty = Type::getInt32Ty(C); + Type *ArgTys[] = {Int32Ty, Int32Ty, Int32Ty}; + Type *FnTy = FunctionType::get(Int32Ty, ArgTys, /*isVarArg=*/false); + Value *Callee = Constant::getNullValue(FnTy->getPointerTo()); + Value *Args[] = { + ConstantInt::get(Int32Ty, 1), + ConstantInt::get(Int32Ty, 2), + ConstantInt::get(Int32Ty, 3) + }; + std::unique_ptr<CallInst> Call(CallInst::Create(Callee, Args, "result")); + + // Test cloning the tail call kind. + CallInst::TailCallKind Kinds[] = {CallInst::TCK_None, CallInst::TCK_Tail, + CallInst::TCK_MustTail}; + for (CallInst::TailCallKind TCK : Kinds) { + Call->setTailCallKind(TCK); + std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone())); + EXPECT_EQ(Call->getTailCallKind(), Clone->getTailCallKind()); + } + Call->setTailCallKind(CallInst::TCK_None); + + // Test cloning an attribute. + { + AttrBuilder AB; + AB.addAttribute(Attribute::ReadOnly); + Call->setAttributes(AttributeSet::get(C, AttributeSet::FunctionIndex, AB)); + std::unique_ptr<CallInst> Clone(cast<CallInst>(Call->clone())); + EXPECT_TRUE(Clone->onlyReadsMemory()); + } +} + } // end anonymous namespace } // end namespace llvm diff --git a/unittests/IR/MDBuilderTest.cpp b/unittests/IR/MDBuilderTest.cpp index 665d559..c8b5a09 100644 --- a/unittests/IR/MDBuilderTest.cpp +++ b/unittests/IR/MDBuilderTest.cpp @@ -9,6 +9,7 @@ #include "llvm/IR/MDBuilder.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Operator.h" #include "gtest/gtest.h" diff --git a/unittests/IR/UserTest.cpp b/unittests/IR/UserTest.cpp new file mode 100644 index 0000000..9c0e7b2 --- /dev/null +++ b/unittests/IR/UserTest.cpp @@ -0,0 +1,96 @@ +//===- llvm/unittest/IR/UserTest.cpp - User 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/AsmParser/Parser.h" +#include "llvm/IR/Function.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/User.h" +#include "llvm/IR/Instructions.h" +#include "llvm/Support/SourceMgr.h" +#include "gtest/gtest.h" +using namespace llvm; + +namespace { + +TEST(UserTest, ValueOpIteration) { + LLVMContext C; + + const char *ModuleString = "define void @f(i32 %x, i32 %y) {\n" + "entry:\n" + " switch i32 undef, label %s0\n" + " [ i32 1, label %s1\n" + " i32 2, label %s2\n" + " i32 3, label %s3\n" + " i32 4, label %s4\n" + " i32 5, label %s5\n" + " i32 6, label %s6\n" + " i32 7, label %s7\n" + " i32 8, label %s8\n" + " i32 9, label %s9 ]\n" + "\n" + "s0:\n" + " br label %exit\n" + "s1:\n" + " br label %exit\n" + "s2:\n" + " br label %exit\n" + "s3:\n" + " br label %exit\n" + "s4:\n" + " br label %exit\n" + "s5:\n" + " br label %exit\n" + "s6:\n" + " br label %exit\n" + "s7:\n" + " br label %exit\n" + "s8:\n" + " br label %exit\n" + "s9:\n" + " br label %exit\n" + "\n" + "exit:\n" + " %phi = phi i32 [ 0, %s0 ], [ 1, %s1 ],\n" + " [ 2, %s2 ], [ 3, %s3 ],\n" + " [ 4, %s4 ], [ 5, %s5 ],\n" + " [ 6, %s6 ], [ 7, %s7 ],\n" + " [ 8, %s8 ], [ 9, %s9 ]\n" + " ret void\n" + "}\n"; + SMDiagnostic Err; + Module *M = ParseAssemblyString(ModuleString, NULL, Err, C); + + Function *F = M->getFunction("f"); + BasicBlock &ExitBB = F->back(); + PHINode &P = cast<PHINode>(ExitBB.front()); + EXPECT_TRUE(P.value_op_begin() == P.value_op_begin()); + EXPECT_FALSE(P.value_op_begin() == P.value_op_end()); + EXPECT_TRUE(P.value_op_begin() != P.value_op_end()); + EXPECT_FALSE(P.value_op_end() != P.value_op_end()); + EXPECT_TRUE(P.value_op_begin() < P.value_op_end()); + EXPECT_FALSE(P.value_op_begin() < P.value_op_begin()); + EXPECT_TRUE(P.value_op_end() > P.value_op_begin()); + EXPECT_FALSE(P.value_op_begin() > P.value_op_begin()); + EXPECT_TRUE(P.value_op_begin() <= P.value_op_begin()); + EXPECT_FALSE(P.value_op_end() <= P.value_op_begin()); + EXPECT_TRUE(P.value_op_begin() >= P.value_op_begin()); + EXPECT_FALSE(P.value_op_begin() >= P.value_op_end()); + EXPECT_EQ(10, std::distance(P.value_op_begin(), P.value_op_end())); + + User::value_op_iterator I = P.value_op_begin(); + I += 3; + EXPECT_EQ(std::next(P.value_op_begin(), 3), I); + EXPECT_EQ(P.getOperand(3), *I); + I++; + EXPECT_EQ(P.getOperand(6), I[2]); + EXPECT_EQ(P.value_op_end(), (I - 2) + 8); +} + +} // end anonymous namespace diff --git a/unittests/IR/VerifierTest.cpp b/unittests/IR/VerifierTest.cpp index 0a660a6..252bdd3 100644 --- a/unittests/IR/VerifierTest.cpp +++ b/unittests/IR/VerifierTest.cpp @@ -52,9 +52,7 @@ TEST(VerifierTest, AliasUnnamedAddr) { GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true, GlobalValue::ExternalLinkage, Init, "foo"); - GlobalAlias *GA = new GlobalAlias(Type::getInt8PtrTy(C), - GlobalValue::ExternalLinkage, - "bar", Aliasee, &M); + auto *GA = GlobalAlias::create(GlobalValue::ExternalLinkage, "bar", Aliasee); GA->setUnnamedAddr(true); std::string Error; raw_string_ostream ErrorOS(Error); |