X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FTransforms%2FUtils%2FCloning.cpp;h=62a280df812f1cd3cfd366a20dbb5c1ca6f06bdc;hb=6f565c0e974e7b420697eba15c16095813ae3d67;hp=b56d453997fd3e8d83cf45e4e2372ace77e33ce1;hpb=cb334476f1dfdfc662bbfe85576b800367fa0f68;p=oota-llvm.git diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index b56d453997f..62a280df812 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -228,14 +228,16 @@ protected: IRBuilder<> IBuilder(C); // Function DI - DIFile File = DBuilder.createFile("filename.c", "/file/dir/"); - 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); + auto *File = DBuilder.createFile("filename.c", "/file/dir/"); + DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None); + DISubroutineType *FuncType = + DBuilder.createSubroutineType(ParamTypes); + auto *CU = + DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c", + "/file/dir", "CloneFunc", false, "", 0); - DISubprogram Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, - FuncType, true, true, 3, 0, false, OldFunc); + auto *Subprogram = DBuilder.createFunction( + CU, "f", "f", File, 4, FuncType, true, true, 3, 0, false, OldFunc); // Function body BasicBlock* Entry = BasicBlock::Create(C, "", OldFunc); @@ -250,12 +252,12 @@ protected: Instruction* Terminator = IBuilder.CreateRetVoid(); // 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); - auto *DL = MDLocation::get(Subprogram->getContext(), 5, 0, Subprogram); + auto *IntType = + DBuilder.createBasicType("int", 32, 0, dwarf::DW_ATE_signed); + auto *E = DBuilder.createExpression(); + auto *Variable = + DBuilder.createAutoVariable(Subprogram, "x", File, 5, IntType, true); + auto *DL = DILocation::get(Subprogram->getContext(), 5, 0, Subprogram); DBuilder.insertDeclare(Alloca, Variable, E, DL, Store); DBuilder.insertDbgValueIntrinsic(AllocaContent, 0, Variable, E, DL, Terminator); @@ -302,9 +304,9 @@ TEST_F(CloneFunc, Subprogram) { EXPECT_EQ(2U, SubprogramCount); auto Iter = Finder->subprograms().begin(); - DISubprogram Sub1 = cast(*Iter); + auto *Sub1 = cast(*Iter); Iter++; - DISubprogram Sub2 = cast(*Iter); + auto *Sub2 = cast(*Iter); EXPECT_TRUE( (Sub1->getFunction() == OldFunc && Sub2->getFunction() == NewFunc) || @@ -319,11 +321,11 @@ TEST_F(CloneFunc, SubprogramInRightCU) { EXPECT_EQ(2U, Finder->compile_unit_count()); auto Iter = Finder->compile_units().begin(); - DICompileUnit CU1 = cast(*Iter); + auto *CU1 = cast(*Iter); Iter++; - DICompileUnit CU2 = cast(*Iter); - EXPECT_TRUE(CU1.getSubprograms().size() == 0 || - CU2.getSubprograms().size() == 0); + auto *CU2 = cast(*Iter); + EXPECT_TRUE(CU1->getSubprograms().size() == 0 || + CU2->getSubprograms().size() == 0); } // Test that instructions in the old function still belong to it in the @@ -350,8 +352,8 @@ TEST_F(CloneFunc, InstructionOwnership) { EXPECT_EQ(OldDL.getCol(), NewDL.getCol()); // But that they belong to different functions - auto *OldSubprogram = cast(OldDL.getScope()); - auto *NewSubprogram = cast(NewDL.getScope()); + auto *OldSubprogram = cast(OldDL.getScope()); + auto *NewSubprogram = cast(NewDL.getScope()); EXPECT_EQ(OldFunc, OldSubprogram->getFunction()); EXPECT_EQ(NewFunc, NewSubprogram->getFunction()); } @@ -388,11 +390,11 @@ TEST_F(CloneFunc, DebugIntrinsics) { // Old variable must belong to the old function EXPECT_EQ(OldFunc, - cast(OldIntrin->getVariable()->getScope()) + cast(OldIntrin->getVariable()->getScope()) ->getFunction()); // New variable must belong to the New function EXPECT_EQ(NewFunc, - cast(NewIntrin->getVariable()->getScope()) + cast(NewIntrin->getVariable()->getScope()) ->getFunction()); } else if (DbgValueInst* OldIntrin = dyn_cast(&OldI)) { DbgValueInst* NewIntrin = dyn_cast(&NewI); @@ -400,11 +402,11 @@ TEST_F(CloneFunc, DebugIntrinsics) { // Old variable must belong to the old function EXPECT_EQ(OldFunc, - cast(OldIntrin->getVariable()->getScope()) + cast(OldIntrin->getVariable()->getScope()) ->getFunction()); // New variable must belong to the New function EXPECT_EQ(NewFunc, - cast(NewIntrin->getVariable()->getScope()) + cast(NewIntrin->getVariable()->getScope()) ->getFunction()); } @@ -413,4 +415,39 @@ TEST_F(CloneFunc, DebugIntrinsics) { } } +class CloneModule : public ::testing::Test { +protected: + void SetUp() override { + SetupModule(); + CreateOldModule(); + CreateNewModule(); + } + + void SetupModule() { OldM = new Module("", C); } + + void CreateOldModule() { + IRBuilder<> IBuilder(C); + + auto *FuncType = FunctionType::get(Type::getVoidTy(C), false); + auto *PersFn = Function::Create(FuncType, GlobalValue::ExternalLinkage, + "persfn", OldM); + auto *F = + Function::Create(FuncType, GlobalValue::PrivateLinkage, "f", OldM); + F->setPersonalityFn(PersFn); + auto *Entry = BasicBlock::Create(C, "", F); + IBuilder.SetInsertPoint(Entry); + IBuilder.CreateRetVoid(); + } + + void CreateNewModule() { NewM = llvm::CloneModule(OldM); } + + LLVMContext C; + Module *OldM; + Module *NewM; +}; + +TEST_F(CloneModule, Verify) { + EXPECT_FALSE(verifyModule(*NewM)); +} + }