mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-10-31 08:16:47 +00:00 
			
		
		
		
	Teach this test not to leak. Also, clean up all the cast<BinaryOperator> cruft.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98446 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		| @@ -11,78 +11,131 @@ | |||||||
| #include "llvm/Argument.h" | #include "llvm/Argument.h" | ||||||
| #include "llvm/Instructions.h" | #include "llvm/Instructions.h" | ||||||
| #include "llvm/LLVMContext.h" | #include "llvm/LLVMContext.h" | ||||||
|  | #include "llvm/ADT/SmallPtrSet.h" | ||||||
|  | #include "llvm/ADT/STLExtras.h" | ||||||
|  |  | ||||||
| using namespace llvm; | 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; |   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 *Add = BinaryOperator::Create(Instruction::Add, V, V); | ||||||
|   BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V); |   BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V); | ||||||
|   BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V); |   BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V); | ||||||
|  |  | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap()); |   BinaryOperator *AddClone = this->clone(Add); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap()); |   BinaryOperator *SubClone = this->clone(Sub); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap()); |   BinaryOperator *MulClone = this->clone(Mul); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap()); |  | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap()); |   EXPECT_FALSE(AddClone->hasNoUnsignedWrap()); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap()); |   EXPECT_FALSE(AddClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_FALSE(SubClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_FALSE(SubClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_FALSE(MulClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_FALSE(MulClone->hasNoSignedWrap()); | ||||||
|  |  | ||||||
|  |   eraseClones(); | ||||||
|  |  | ||||||
|   Add->setHasNoUnsignedWrap(); |   Add->setHasNoUnsignedWrap(); | ||||||
|   Sub->setHasNoUnsignedWrap(); |   Sub->setHasNoUnsignedWrap(); | ||||||
|   Mul->setHasNoUnsignedWrap(); |   Mul->setHasNoUnsignedWrap(); | ||||||
|  |  | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap()); |   AddClone = this->clone(Add); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap()); |   SubClone = this->clone(Sub); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap()); |   MulClone = this->clone(Mul); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap()); |  | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap()); |   EXPECT_TRUE(AddClone->hasNoUnsignedWrap()); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap()); |   EXPECT_FALSE(AddClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_TRUE(SubClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_FALSE(SubClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_TRUE(MulClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_FALSE(MulClone->hasNoSignedWrap()); | ||||||
|  |  | ||||||
|  |   eraseClones(); | ||||||
|  |  | ||||||
|   Add->setHasNoSignedWrap(); |   Add->setHasNoSignedWrap(); | ||||||
|   Sub->setHasNoSignedWrap(); |   Sub->setHasNoSignedWrap(); | ||||||
|   Mul->setHasNoSignedWrap(); |   Mul->setHasNoSignedWrap(); | ||||||
|  |  | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap()); |   AddClone = this->clone(Add); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap()); |   SubClone = this->clone(Sub); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap()); |   MulClone = this->clone(Mul); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap()); |  | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap()); |   EXPECT_TRUE(AddClone->hasNoUnsignedWrap()); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap()); |   EXPECT_TRUE(AddClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_TRUE(SubClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_TRUE(SubClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_TRUE(MulClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_TRUE(MulClone->hasNoSignedWrap()); | ||||||
|  |  | ||||||
|  |   eraseClones(); | ||||||
|  |  | ||||||
|   Add->setHasNoUnsignedWrap(false); |   Add->setHasNoUnsignedWrap(false); | ||||||
|   Sub->setHasNoUnsignedWrap(false); |   Sub->setHasNoUnsignedWrap(false); | ||||||
|   Mul->setHasNoUnsignedWrap(false); |   Mul->setHasNoUnsignedWrap(false); | ||||||
|  |  | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Add->clone())->hasNoUnsignedWrap()); |   AddClone = this->clone(Add); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Add->clone())->hasNoSignedWrap()); |   SubClone = this->clone(Sub); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Sub->clone())->hasNoUnsignedWrap()); |   MulClone = this->clone(Mul); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Sub->clone())->hasNoSignedWrap()); |  | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(Mul->clone())->hasNoUnsignedWrap()); |   EXPECT_FALSE(AddClone->hasNoUnsignedWrap()); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(Mul->clone())->hasNoSignedWrap()); |   EXPECT_TRUE(AddClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_FALSE(SubClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_TRUE(SubClone->hasNoSignedWrap()); | ||||||
|  |   EXPECT_FALSE(MulClone->hasNoUnsignedWrap()); | ||||||
|  |   EXPECT_TRUE(MulClone->hasNoSignedWrap()); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST(CloneInstruction, Inbounds) { | TEST_F(CloneInstruction, Inbounds) { | ||||||
|   LLVMContext context; |   V = new Argument(Type::getInt32PtrTy(context)); | ||||||
|   Value *V = new Argument(Type::getInt32PtrTy(context)); |  | ||||||
|   Constant *Z = Constant::getNullValue(Type::getInt32Ty(context)); |   Constant *Z = Constant::getNullValue(Type::getInt32Ty(context)); | ||||||
|   std::vector<Value *> ops; |   std::vector<Value *> ops; | ||||||
|   ops.push_back(Z); |   ops.push_back(Z); | ||||||
|   GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end()); |   GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end()); | ||||||
|   EXPECT_FALSE(cast<GetElementPtrInst>(GEP->clone())->isInBounds()); |   EXPECT_FALSE(this->clone(GEP)->isInBounds()); | ||||||
|  |  | ||||||
|   GEP->setIsInBounds(); |   GEP->setIsInBounds(); | ||||||
|   EXPECT_TRUE(cast<GetElementPtrInst>(GEP->clone())->isInBounds()); |   EXPECT_TRUE(this->clone(GEP)->isInBounds()); | ||||||
| } | } | ||||||
|  |  | ||||||
| TEST(CloneInstruction, Exact) { | TEST_F(CloneInstruction, Exact) { | ||||||
|   LLVMContext context; |   V = new Argument(Type::getInt32Ty(context)); | ||||||
|   Value *V = new Argument(Type::getInt32Ty(context)); |  | ||||||
|  |  | ||||||
|   BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V); |   BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V); | ||||||
|   EXPECT_FALSE(cast<BinaryOperator>(SDiv->clone())->isExact()); |   EXPECT_FALSE(this->clone(SDiv)->isExact()); | ||||||
|  |  | ||||||
|   SDiv->setIsExact(true); |   SDiv->setIsExact(true); | ||||||
|   EXPECT_TRUE(cast<BinaryOperator>(SDiv->clone())->isExact()); |   EXPECT_TRUE(this->clone(SDiv)->isExact()); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user