Move the complex address expression out of DIVariable and into an extra
[oota-llvm.git] / unittests / Transforms / Utils / Cloning.cpp
index 6f8cf95fb5a7c7c7eb70b2db2628e3484f7b16d3..c7799795d9be94a1f56649853c402c528b8a5cc9 100644 (file)
@@ -10,6 +10,7 @@
 #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"
@@ -24,8 +25,6 @@
 #include "llvm/IR/LLVMContext.h"
 #include "gtest/gtest.h"
 
-#include <set>
-
 using namespace llvm;
 
 namespace {
@@ -33,44 +32,40 @@ namespace {
 class CloneInstruction : public ::testing::Test {
 protected:
   virtual void SetUp() {
-    V = NULL;
+    V = nullptr;
   }
 
   template <typename T>
   T *clone(T *V1) {
     Value *V2 = V1->clone();
-    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));
+    Orig.insert(V1);
+    Clones.insert(V2);
     return cast<T>(V2);
   }
 
-  void eraseClones() { Clones.clear(); }
+  void eraseClones() {
+    DeleteContainerPointers(Clones);
+  }
 
   virtual void TearDown() {
     eraseClones();
-    Orig.clear();
-    V.reset();
+    DeleteContainerPointers(Orig);
+    delete V;
   }
 
-  std::set<std::unique_ptr<Value>> Orig;   // Erase on exit
-  std::set<std::unique_ptr<Value>> Clones; // Erase in eraseClones
+  SmallPtrSet<Value *, 4> Orig;   // Erase on exit
+  SmallPtrSet<Value *, 4> Clones; // Erase in eraseClones
 
   LLVMContext context;
-  std::unique_ptr<Value> V;
+  Value *V;
 };
 
 TEST_F(CloneInstruction, OverflowBits) {
-  V = make_unique<Argument>(Type::getInt32Ty(context));
+  V = new Argument(Type::getInt32Ty(context));
 
-  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 *Add = BinaryOperator::Create(Instruction::Add, V, V);
+  BinaryOperator *Sub = BinaryOperator::Create(Instruction::Sub, V, V);
+  BinaryOperator *Mul = BinaryOperator::Create(Instruction::Mul, V, V);
 
   BinaryOperator *AddClone = this->clone(Add);
   BinaryOperator *SubClone = this->clone(Sub);
@@ -136,12 +131,12 @@ TEST_F(CloneInstruction, OverflowBits) {
 }
 
 TEST_F(CloneInstruction, Inbounds) {
-  V = make_unique<Argument>(Type::getInt32PtrTy(context));
+  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.get(), ops);
+  GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops);
   EXPECT_FALSE(this->clone(GEP)->isInBounds());
 
   GEP->setIsInBounds();
@@ -149,10 +144,9 @@ TEST_F(CloneInstruction, Inbounds) {
 }
 
 TEST_F(CloneInstruction, Exact) {
-  V = make_unique<Argument>(Type::getInt32Ty(context));
+  V = new Argument(Type::getInt32Ty(context));
 
-  BinaryOperator *SDiv =
-      BinaryOperator::Create(Instruction::SDiv, V.get(), V.get());
+  BinaryOperator *SDiv = BinaryOperator::Create(Instruction::SDiv, V, V);
   EXPECT_FALSE(this->clone(SDiv)->isExact());
 
   SDiv->setIsExact(true);
@@ -238,7 +232,7 @@ protected:
 
     // Function DI
     DIFile File = DBuilder.createFile("filename.c", "/file/dir/");
-    DIArray ParamTypes = DBuilder.getOrCreateArray(ArrayRef<Value*>());
+    DITypeArray ParamTypes = DBuilder.getOrCreateTypeArray(None);
     DICompositeType FuncType = DBuilder.createSubroutineType(File, ParamTypes);
     DICompileUnit CU = DBuilder.createCompileUnit(dwarf::DW_LANG_C99,
         "filename.c", "/file/dir", "CloneFunc", false, "", 0);
@@ -261,10 +255,11 @@ protected:
     // Create a local variable around the alloca
     DIType IntType = DBuilder.createBasicType("int", 32, 0,
         dwarf::DW_ATE_signed);
+    DIExpression E = DBuilder.createExpression();
     DIVariable Variable = DBuilder.createLocalVariable(
       dwarf::DW_TAG_auto_variable, Subprogram, "x", File, 5, IntType, true);
-    DBuilder.insertDeclare(Alloca, Variable, Store);
-    DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, Terminator);
+    DBuilder.insertDeclare(Alloca, Variable, E, Store);
+    DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, Terminator);
     // Finalize the debug info
     DBuilder.finalize();
 
@@ -278,7 +273,7 @@ protected:
 
   void CreateNewFunc() {
     ValueToValueMapTy VMap;
-    NewFunc = CloneFunction(OldFunc, VMap, true, NULL);
+    NewFunc = CloneFunction(OldFunc, VMap, true, nullptr);
     M->getFunctionList().push_back(NewFunc);
   }