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);
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);
EXPECT_EQ(2U, SubprogramCount);
auto Iter = Finder->subprograms().begin();
- DISubprogram Sub1 = cast<MDSubprogram>(*Iter);
+ auto *Sub1 = cast<DISubprogram>(*Iter);
Iter++;
- DISubprogram Sub2 = cast<MDSubprogram>(*Iter);
+ auto *Sub2 = cast<DISubprogram>(*Iter);
EXPECT_TRUE(
(Sub1->getFunction() == OldFunc && Sub2->getFunction() == NewFunc) ||
EXPECT_EQ(2U, Finder->compile_unit_count());
auto Iter = Finder->compile_units().begin();
- DICompileUnit CU1 = cast<MDCompileUnit>(*Iter);
+ auto *CU1 = cast<DICompileUnit>(*Iter);
Iter++;
- DICompileUnit CU2 = cast<MDCompileUnit>(*Iter);
- EXPECT_TRUE(CU1.getSubprograms().size() == 0 ||
- CU2.getSubprograms().size() == 0);
+ auto *CU2 = cast<DICompileUnit>(*Iter);
+ EXPECT_TRUE(CU1->getSubprograms().size() == 0 ||
+ CU2->getSubprograms().size() == 0);
}
// Test that instructions in the old function still belong to it in the
EXPECT_EQ(OldDL.getCol(), NewDL.getCol());
// But that they belong to different functions
- auto *OldSubprogram = cast<MDSubprogram>(OldDL.getScope());
- auto *NewSubprogram = cast<MDSubprogram>(NewDL.getScope());
+ auto *OldSubprogram = cast<DISubprogram>(OldDL.getScope());
+ auto *NewSubprogram = cast<DISubprogram>(NewDL.getScope());
EXPECT_EQ(OldFunc, OldSubprogram->getFunction());
EXPECT_EQ(NewFunc, NewSubprogram->getFunction());
}
// Old variable must belong to the old function
EXPECT_EQ(OldFunc,
- cast<MDSubprogram>(OldIntrin->getVariable()->getScope())
+ cast<DISubprogram>(OldIntrin->getVariable()->getScope())
->getFunction());
// New variable must belong to the New function
EXPECT_EQ(NewFunc,
- cast<MDSubprogram>(NewIntrin->getVariable()->getScope())
+ cast<DISubprogram>(NewIntrin->getVariable()->getScope())
->getFunction());
} else if (DbgValueInst* OldIntrin = dyn_cast<DbgValueInst>(&OldI)) {
DbgValueInst* NewIntrin = dyn_cast<DbgValueInst>(&NewI);
// Old variable must belong to the old function
EXPECT_EQ(OldFunc,
- cast<MDSubprogram>(OldIntrin->getVariable()->getScope())
+ cast<DISubprogram>(OldIntrin->getVariable()->getScope())
->getFunction());
// New variable must belong to the New function
EXPECT_EQ(NewFunc,
- cast<MDSubprogram>(NewIntrin->getVariable()->getScope())
+ cast<DISubprogram>(NewIntrin->getVariable()->getScope())
->getFunction());
}
}
}
+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));
+}
+
}