@@ -847,7 +847,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
847847
848848 llvm::DIModule *getOrCreateModule (const void *Key, llvm::DIScope *Parent,
849849 StringRef Name, StringRef IncludePath,
850- StringRef CompDir,
851850 uint64_t Signature = ~1ULL ,
852851 StringRef ASTFile = StringRef()) {
853852 // Look in the cache first.
@@ -857,7 +856,6 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
857856
858857 std::string RemappedIncludePath = DebugPrefixMap.remapPath (IncludePath);
859858 std::string RemappedASTFile = DebugPrefixMap.remapPath (ASTFile);
860- std::string RemappedCompDir = DebugPrefixMap.remapPath (CompDir);
861859
862860 // For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
863861 if (!Opts.DisableClangModuleSkeletonCUs ) {
@@ -867,7 +865,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
867865 llvm::DIBuilder DIB (M);
868866 DIB.createCompileUnit (IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
869867 : llvm::dwarf::DW_LANG_C99,
870- DIB.createFile (Name, RemappedCompDir ),
868+ DIB.createFile (Name, RemappedIncludePath ),
871869 TheCU->getProducer (), true , StringRef (), 0 ,
872870 RemappedASTFile, llvm::DICompileUnit::FullDebug,
873871 Signature);
@@ -894,8 +892,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
894892 uint64_t Signature =
895893 Desc.getSignature () ? Desc.getSignature ().truncatedValue () : ~1ULL ;
896894
897- StringRef CompDir = Opts.DebugCompilationDir ;
898- StringRef IncludePath = Desc.getPath ();
895+ // Clang modules using fmodule-file-home-is-cwd should have their
896+ // include path set to the working directory.
897+ auto &HSI =
898+ CI.getClangPreprocessor ().getHeaderSearchInfo ().getHeaderSearchOpts ();
899+ StringRef IncludePath =
900+ HSI.ModuleFileHomeIsCwd ? Opts.DebugCompilationDir : Desc.getPath ();
899901
900902 // Handle Clang modules.
901903 if (ClangModule) {
@@ -917,13 +919,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
917919 ClangModule->Parent );
918920 }
919921 return getOrCreateModule (ClangModule, Parent, Desc.getModuleName (),
920- IncludePath, CompDir, Signature,
921- Desc.getASTFile ());
922+ IncludePath, Signature, Desc.getASTFile ());
922923 }
923924 // Handle PCH.
924925 return getOrCreateModule (Desc.getASTFile ().bytes_begin (), nullptr ,
925- Desc.getModuleName (), IncludePath, CompDir ,
926- Signature, Desc.getASTFile ());
926+ Desc.getModuleName (), IncludePath, Signature ,
927+ Desc.getASTFile ());
927928 };
928929
929930 static std::optional<ASTSourceDescriptor>
@@ -946,7 +947,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
946947 // the module on disk is Bar (.swiftmodule or .swiftinterface), and is used
947948 // for loading and mangling.
948949 StringRef Name = M->getRealName ().str ();
949- return getOrCreateModule (M, TheCU, Name, Path, Opts. DebugCompilationDir );
950+ return getOrCreateModule (M, TheCU, Name, Path);
950951 }
951952
952953 TypeAliasDecl *getMetadataType (StringRef ArchetypeName) {
@@ -2542,8 +2543,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25422543 auto Identifier = IGM.getSILModule ().getASTContext ().getIdentifier (
25432544 Attribute->ManglingModuleName );
25442545 void *Key = (void *)Identifier.get ();
2545- Scope = getOrCreateModule (Key, TheCU, Attribute-> ManglingModuleName , {},
2546- {});
2546+ Scope =
2547+ getOrCreateModule (Key, TheCU, Attribute-> ManglingModuleName , {});
25472548 } else {
25482549 Context = ND->getParent ();
25492550 }
@@ -2790,8 +2791,7 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
27902791 // Create a module for the current compile unit.
27912792 auto *MDecl = IGM.getSwiftModule ();
27922793 llvm::sys::path::remove_filename (SourcePath);
2793- MainModule = getOrCreateModule (MDecl, TheCU, Opts.ModuleName , SourcePath,
2794- Opts.DebugCompilationDir );
2794+ MainModule = getOrCreateModule (MDecl, TheCU, Opts.ModuleName , SourcePath);
27952795 DBuilder.createImportedModule (MainFile, MainModule, MainFile, 0 );
27962796
27972797 // Macro definitions that were defined by the user with "-Xcc -D" on the
0 commit comments