summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2010-03-16 16:51:38 +0000
committerrdivacky <rdivacky@FreeBSD.org>2010-03-16 16:51:38 +0000
commit0f448b841684305c051796982f300c9bff959307 (patch)
tree458dd25677a43aef6390ecadb4423817f00e08b0 /unittests
parent9e2446b38c94db61b2416c28fee415c03663c11c (diff)
downloadFreeBSD-src-0f448b841684305c051796982f300c9bff959307.zip
FreeBSD-src-0f448b841684305c051796982f300c9bff959307.tar.gz
Update LLVM to r98631.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Transforms/Utils/Cloning.cpp125
-rw-r--r--unittests/VMCore/InstructionsTest.cpp41
-rw-r--r--unittests/VMCore/MetadataTest.cpp4
-rw-r--r--unittests/VMCore/PassManagerTest.cpp4
-rw-r--r--unittests/VMCore/VerifierTest.cpp7
5 files changed, 138 insertions, 43 deletions
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp
index 17047e7..b65ac34 100644
--- a/unittests/Transforms/Utils/Cloning.cpp
+++ b/unittests/Transforms/Utils/Cloning.cpp
@@ -11,78 +11,131 @@
#include "llvm/Argument.h"
#include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/STLExtras.h"
using namespace llvm;
-TEST(CloneInstruction, OverflowBits) {
+class CloneInstruction : public ::testing::Test {
+protected:
+ virtual void SetUp() {
+ V = NULL;
+ }
+
+ template <typename T>
+ T *clone(T *V1) {
+ Value *V2 = V1->clone();
+ Orig.insert(V1);
+ Clones.insert(V2);
+ return cast<T>(V2);
+ }
+
+ void eraseClones() {
+ DeleteContainerPointers(Clones);
+ }
+
+ virtual void TearDown() {
+ eraseClones();
+ DeleteContainerPointers(Orig);
+ delete V;
+ }
+
+ SmallPtrSet<Value *, 4> Orig; // Erase on exit
+ SmallPtrSet<Value *, 4> Clones; // Erase in eraseClones
+
LLVMContext context;
- Value *V = new Argument(Type::getInt32Ty(context));
+ Value *V;
+};
+
+TEST_F(CloneInstruction, OverflowBits) {
+ V = new Argument(Type::getInt32Ty(context));
BinaryOperator *Add = BinaryOperator::Create(Instruction::Add, V, V);
BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
- EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
+ BinaryOperator *AddClone = this->clone(Add);
+ BinaryOperator *SubClone = this->clone(Sub);
+ BinaryOperator *MulClone = this->clone(Mul);
+
+ EXPECT_FALSE(AddClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(AddClone->hasNoSignedWrap());
+ EXPECT_FALSE(SubClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(SubClone->hasNoSignedWrap());
+ EXPECT_FALSE(MulClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(MulClone->hasNoSignedWrap());
+
+ eraseClones();
Add->setHasNoUnsignedWrap();
Sub->setHasNoUnsignedWrap();
Mul->setHasNoUnsignedWrap();
- EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
+ AddClone = this->clone(Add);
+ SubClone = this->clone(Sub);
+ MulClone = this->clone(Mul);
+
+ EXPECT_TRUE(AddClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(AddClone->hasNoSignedWrap());
+ EXPECT_TRUE(SubClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(SubClone->hasNoSignedWrap());
+ EXPECT_TRUE(MulClone->hasNoUnsignedWrap());
+ EXPECT_FALSE(MulClone->hasNoSignedWrap());
+
+ eraseClones();
Add->setHasNoSignedWrap();
Sub->setHasNoSignedWrap();
Mul->setHasNoSignedWrap();
- EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
+ AddClone = this->clone(Add);
+ SubClone = this->clone(Sub);
+ MulClone = this->clone(Mul);
+
+ EXPECT_TRUE(AddClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(AddClone->hasNoSignedWrap());
+ EXPECT_TRUE(SubClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(SubClone->hasNoSignedWrap());
+ EXPECT_TRUE(MulClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(MulClone->hasNoSignedWrap());
+
+ eraseClones();
Add->setHasNoUnsignedWrap(false);
Sub->setHasNoUnsignedWrap(false);
Mul->setHasNoUnsignedWrap(false);
- EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap());
- EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap());
- EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap());
+ AddClone = this->clone(Add);
+ SubClone = this->clone(Sub);
+ MulClone = this->clone(Mul);
+
+ EXPECT_FALSE(AddClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(AddClone->hasNoSignedWrap());
+ EXPECT_FALSE(SubClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(SubClone->hasNoSignedWrap());
+ EXPECT_FALSE(MulClone->hasNoUnsignedWrap());
+ EXPECT_TRUE(MulClone->hasNoSignedWrap());
}
-TEST(CloneInstruction, Inbounds) {
- LLVMContext context;
- Value *V = new Argument(Type::getInt32PtrTy(context));
+TEST_F(CloneInstruction, Inbounds) {
+ V = new Argument(Type::getInt32PtrTy(context));
+
Constant *Z = Constant::getNullValue(Type::getInt32Ty(context));
std::vector<Value *> ops;
ops.push_back(Z);
GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end());
- EXPECT_FALSE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
+ EXPECT_FALSE(this->clone(GEP)->isInBounds());
GEP->setIsInBounds();
- EXPECT_TRUE(cast<GetElementPtrInst>(GEP->clone())->isInBounds());
+ EXPECT_TRUE(this->clone(GEP)->isInBounds());
}
-TEST(CloneInstruction, Exact) {
- LLVMContext context;
- Value *V = new Argument(Type::getInt32Ty(context));
+TEST_F(CloneInstruction, Exact) {
+ V = new Argument(Type::getInt32Ty(context));
BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
- EXPECT_FALSE(cast<BinaryOperator>(SDiv->clone())->isExact());
+ EXPECT_FALSE(this->clone(SDiv)->isExact());
SDiv->setIsExact(true);
- EXPECT_TRUE(cast<BinaryOperator>(SDiv->clone())->isExact());
+ EXPECT_TRUE(this->clone(SDiv)->isExact());
}
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
new file mode 100644
index 0000000..2d98cad
--- /dev/null
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -0,0 +1,41 @@
+//===- llvm/unittest/VMCore/InstructionsTest.cpp - Instructions 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/Instructions.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/LLVMContext.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+namespace {
+
+TEST(InstructionsTest, ReturnInst) {
+ LLVMContext &C(getGlobalContext());
+
+ // test for PR6589
+ const ReturnInst* r0 = ReturnInst::Create(C);
+ EXPECT_EQ(r0->op_begin(), r0->op_end());
+
+ const IntegerType* Int1 = IntegerType::get(C, 1);
+ Constant* One = ConstantInt::get(Int1, 1, true);
+ const ReturnInst* r1 = ReturnInst::Create(C, One);
+ User::const_op_iterator b(r1->op_begin());
+ EXPECT_NE(b, r1->op_end());
+ EXPECT_EQ(*b, One);
+ EXPECT_EQ(r1->getOperand(0), One);
+ ++b;
+ EXPECT_EQ(b, r1->op_end());
+
+ // clean up
+ delete r0;
+ delete r1;
+}
+
+} // end anonymous namespace
+} // end namespace llvm
diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp
index 13bf27e..04db486 100644
--- a/unittests/VMCore/MetadataTest.cpp
+++ b/unittests/VMCore/MetadataTest.cpp
@@ -132,9 +132,9 @@ TEST(NamedMDNodeTest, Search) {
MDNode *Nodes[2] = { n, n2 };
- Module *M = new Module("MyModule", Context);
+ Module M("MyModule", Context);
const char *Name = "llvm.NMD1";
- NamedMDNode *NMD = NamedMDNode::Create(Context, Name, &Nodes[0], 2, M);
+ NamedMDNode *NMD = NamedMDNode::Create(Context, Name, &Nodes[0], 2, &M);
std::string Str;
raw_string_ostream oss(Str);
NMD->print(oss);
diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp
index cb8f9eb..bc21298 100644
--- a/unittests/VMCore/PassManagerTest.cpp
+++ b/unittests/VMCore/PassManagerTest.cpp
@@ -324,10 +324,10 @@ namespace llvm {
template<typename T>
void MemoryTestHelper(int run) {
- Module *M = makeLLVMModule();
+ OwningPtr<Module> M(makeLLVMModule());
T *P = new T();
PassManager Passes;
- Passes.add(new TargetData(M));
+ Passes.add(new TargetData(M.get()));
Passes.add(P);
Passes.run(*M);
T::finishedOK(run);
diff --git a/unittests/VMCore/VerifierTest.cpp b/unittests/VMCore/VerifierTest.cpp
index c8838c5..1173b2d 100644
--- a/unittests/VMCore/VerifierTest.cpp
+++ b/unittests/VMCore/VerifierTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/Function.h"
#include "llvm/Instructions.h"
#include "llvm/LLVMContext.h"
+#include "llvm/ADT/OwningPtr.h"
#include "llvm/Analysis/Verifier.h"
#include "gtest/gtest.h"
@@ -21,9 +22,9 @@ namespace {
TEST(VerifierTest, Branch_i1) {
LLVMContext &C = getGlobalContext();
FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
- Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage);
- BasicBlock *Entry = BasicBlock::Create(C, "entry", F);
- BasicBlock *Exit = BasicBlock::Create(C, "exit", F);
+ OwningPtr<Function> F(Function::Create(FTy, GlobalValue::ExternalLinkage));
+ BasicBlock *Entry = BasicBlock::Create(C, "entry", F.get());
+ BasicBlock *Exit = BasicBlock::Create(C, "exit", F.get());
ReturnInst::Create(C, Exit);
// To avoid triggering an assertion in BranchInst::Create, we first create
OpenPOWER on IntegriCloud