Index: include/llvm/IR/DIBuilder.h =================================================================== --- include/llvm/IR/DIBuilder.h +++ include/llvm/IR/DIBuilder.h @@ -83,8 +83,7 @@ /// A CompileUnit provides an anchor for all debugging /// information generated during this instance of compilation. /// \param Lang Source programming language, eg. dwarf::DW_LANG_C99 - /// \param File File name - /// \param Dir Directory + /// \param File File info. /// \param Producer Identify the producer of debugging information /// and code. Usually this is a compiler /// version string. @@ -101,9 +100,9 @@ /// \param Kind The kind of debug information to generate. /// \param DWOId The DWOId if this is a split skeleton compile unit. DICompileUnit * - createCompileUnit(unsigned Lang, StringRef File, StringRef Dir, - StringRef Producer, bool isOptimized, StringRef Flags, - unsigned RV, StringRef SplitName = StringRef(), + createCompileUnit(unsigned Lang, DIFile *File, StringRef Producer, + bool isOptimized, StringRef Flags, unsigned RV, + StringRef SplitName = StringRef(), DICompileUnit::DebugEmissionKind Kind = DICompileUnit::DebugEmissionKind::FullDebug, uint64_t DWOId = 0, bool SplitDebugInlining = true); Index: lib/IR/DIBuilder.cpp =================================================================== --- lib/IR/DIBuilder.cpp +++ lib/IR/DIBuilder.cpp @@ -109,22 +109,20 @@ } DICompileUnit *DIBuilder::createCompileUnit( - unsigned Lang, StringRef Filename, StringRef Directory, StringRef Producer, - bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName, + unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, + StringRef Flags, unsigned RunTimeVer, StringRef SplitName, DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, bool SplitDebugInlining) { assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && "Invalid Language tag"); - assert(!Filename.empty() && - "Unable to create compile unit without filename"); assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); CUNode = DICompileUnit::getDistinct( - VMContext, Lang, DIFile::get(VMContext, Filename, Directory), Producer, - isOptimized, Flags, RunTimeVer, SplitName, Kind, nullptr, nullptr, - nullptr, nullptr, nullptr, DWOId, SplitDebugInlining); + VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, + SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, + SplitDebugInlining); // Create a named metadata so that it is easier to find cu in a module. NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); Index: unittests/IR/IRBuilderTest.cpp =================================================================== --- unittests/IR/IRBuilderTest.cpp +++ unittests/IR/IRBuilderTest.cpp @@ -340,8 +340,9 @@ IRBuilder<> Builder(BB); DIBuilder DIB(*M); auto File = DIB.createFile("F.CBL", "/"); - auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/", - "llvm-cobol74", true, "", 0); + auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, + DIB.createFile("F.CBL", "/"), "llvm-cobol74", + true, "", 0); auto Type = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None)); auto SP = DIB.createFunction(CU, "foo", "", File, 1, Type, false, true, 1, DINode::FlagZero, true); @@ -392,8 +393,9 @@ DIBuilder DIB(*M); auto File = DIB.createFile("tmp.cpp", "/"); - auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C_plus_plus_11, "tmp.cpp", "/", - "", true, "", 0); + auto CU = DIB.createCompileUnit(dwarf::DW_LANG_C_plus_plus_11, + DIB.createFile("tmp.cpp", "/"), "", true, "", + 0); auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None)); auto SP = DIB.createFunction(CU, "foo", "foo", File, 1, SPType, false, true, 1); @@ -422,8 +424,9 @@ TEST_F(IRBuilderTest, DIImportedEntity) { IRBuilder<> Builder(BB); DIBuilder DIB(*M); - auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, "F.CBL", "/", - "llvm-cobol74", true, "", 0); + auto CU = DIB.createCompileUnit(dwarf::DW_LANG_Cobol74, + DIB.createFile("F.CBL", "/"), "llvm-cobol74", + true, "", 0); DIB.createImportedDeclaration(CU, nullptr, 1); DIB.createImportedDeclaration(CU, nullptr, 1); DIB.createImportedModule(CU, (DIImportedEntity *)nullptr, 2); Index: unittests/IR/VerifierTest.cpp =================================================================== --- unittests/IR/VerifierTest.cpp +++ unittests/IR/VerifierTest.cpp @@ -154,8 +154,8 @@ LLVMContext C; Module M("M", C); DIBuilder DIB(M); - DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/", "unittest", - false, "", 0); + DIB.createCompileUnit(dwarf::DW_LANG_C89, DIB.createFile("broken.c", "/"), + "unittest", false, "", 0); DIB.finalize(); EXPECT_FALSE(verifyModule(M)); @@ -176,7 +176,8 @@ LLVMContext C; Module M("M", C); DIBuilder DIB(M); - auto *CU = DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/", + auto *CU = DIB.createCompileUnit(dwarf::DW_LANG_C89, + DIB.createFile("broken.c", "/"), "unittest", false, "", 0); new GlobalVariable(M, Type::getInt8Ty(C), false, GlobalValue::ExternalLinkage, nullptr, "g"); @@ -208,7 +209,7 @@ LLVMContext C; Module M("M", C); DIBuilder DIB(M); - DIB.createCompileUnit(dwarf::DW_LANG_C89, "broken.c", "/", + DIB.createCompileUnit(dwarf::DW_LANG_C89, DIB.createFile("broken.c", "/"), "unittest", false, "", 0); DIB.finalize(); EXPECT_FALSE(verifyModule(M)); Index: unittests/Transforms/Utils/Cloning.cpp =================================================================== --- unittests/Transforms/Utils/Cloning.cpp +++ unittests/Transforms/Utils/Cloning.cpp @@ -231,9 +231,10 @@ 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); + auto *CU = DBuilder.createCompileUnit(dwarf::DW_LANG_C99, + DBuilder.createFile("filename.c", + "/file/dir"), + "CloneFunc", false, "", 0); auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, FuncType, true, true, 3, @@ -268,7 +269,8 @@ // Create another, empty, compile unit DIBuilder DBuilder2(*M); DBuilder2.createCompileUnit(dwarf::DW_LANG_C99, - "extra.c", "/file/dir", "CloneFunc", false, "", 0); + DBuilder.createFile("extra.c", "/file/dir"), + "CloneFunc", false, "", 0); DBuilder2.finalize(); } @@ -422,9 +424,10 @@ auto *File = DBuilder.createFile("filename.c", "/file/dir/"); DITypeRefArray ParamTypes = DBuilder.getOrCreateTypeArray(None); DISubroutineType *DFuncType = DBuilder.createSubroutineType(ParamTypes); - auto *CU = - DBuilder.createCompileUnit(dwarf::DW_LANG_C99, "filename.c", - "/file/dir", "CloneModule", false, "", 0); + auto *CU = DBuilder.createCompileUnit(dwarf::DW_LANG_C99, + DBuilder.createFile("filename.c", + "/file/dir"), + "CloneModule", false, "", 0); // Function DI auto *Subprogram = DBuilder.createFunction(CU, "f", "f", File, 4, DFuncType, true, true, 3,