diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-21 23:47:47 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-21 23:47:47 +0000 |
commit | 6d73b8016ebbea956fd19a7e28a668b9195a192c (patch) | |
tree | ce1bbc493b206b2babb266457c7070bbc739693c /unittests | |
parent | b5213bb1b0639e48b82e84886e0d8aca6ede5cba (diff) | |
download | llvm-6d73b8016ebbea956fd19a7e28a668b9195a192c.tar.gz llvm-6d73b8016ebbea956fd19a7e28a668b9195a192c.tar.bz2 llvm-6d73b8016ebbea956fd19a7e28a668b9195a192c.tar.xz |
Use unique_ptr to handle ownership of Value*s in Cloning unit tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206828 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Transforms/Utils/Cloning.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index fb27dc1735..6f8cf95fb5 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -10,7 +10,6 @@ #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/SmallPtrSet.h" #include "llvm/IR/Argument.h" #include "llvm/IR/Constant.h" #include "llvm/IR/DebugInfo.h" @@ -25,6 +24,8 @@ #include "llvm/IR/LLVMContext.h" #include "gtest/gtest.h" +#include <set> + using namespace llvm; namespace { @@ -38,34 +39,38 @@ protected: template <typename T> T *clone(T *V1) { Value *V2 = V1->clone(); - Orig.insert(V1); - Clones.insert(V2); + std::unique_ptr<Value> V(V1); + if (!Orig.insert(std::move(V)).second) + V.release(); // this wasn't the first time we added the element, so the + // set already had ownership + Clones.insert(std::unique_ptr<Value>(V2)); return cast<T>(V2); } - void eraseClones() { - DeleteContainerPointers(Clones); - } + void eraseClones() { Clones.clear(); } virtual void TearDown() { eraseClones(); - DeleteContainerPointers(Orig); - delete V; + Orig.clear(); + V.reset(); } - SmallPtrSet<Value *, 4> Orig; // Erase on exit - SmallPtrSet<Value *, 4> Clones; // Erase in eraseClones + std::set<std::unique_ptr<Value>> Orig; // Erase on exit + std::set<std::unique_ptr<Value>> Clones; // Erase in eraseClones LLVMContext context; - Value *V; + std::unique_ptr<Value> V; }; TEST_F(CloneInstruction, OverflowBits) { - V = new Argument(Type::getInt32Ty(context)); + V = make_unique<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); + BinaryOperator *Add = + BinaryOperator::Create(Instruction::Add, V.get(), V.get()); + BinaryOperator *Sub = + BinaryOperator::Create(Instruction::Sub, V.get(), V.get()); + BinaryOperator *Mul = + BinaryOperator::Create(Instruction::Mul, V.get(), V.get()); BinaryOperator *AddClone = this->clone(Add); BinaryOperator *SubClone = this->clone(Sub); @@ -131,12 +136,12 @@ TEST_F(CloneInstruction, OverflowBits) { } TEST_F(CloneInstruction, Inbounds) { - V = new Argument(Type::getInt32PtrTy(context)); + V = make_unique<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); + GetElementPtrInst *GEP = GetElementPtrInst::Create(V.get(), ops); EXPECT_FALSE(this->clone(GEP)->isInBounds()); GEP->setIsInBounds(); @@ -144,9 +149,10 @@ TEST_F(CloneInstruction, Inbounds) { } TEST_F(CloneInstruction, Exact) { - V = new Argument(Type::getInt32Ty(context)); + V = make_unique<Argument>(Type::getInt32Ty(context)); - BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V); + BinaryOperator *SDiv = + BinaryOperator::Create(Instruction::SDiv, V.get(), V.get()); EXPECT_FALSE(this->clone(SDiv)->isExact()); SDiv->setIsExact(true); |