Skip to content

Commit f91f8c5

Browse files
Merge pull request swiftlang#81563 from rastogishubham/CompDir
Set the Compilation directory when generating the Skeleton CU
2 parents d5da3e2 + b286b1c commit f91f8c5

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
855855

856856
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
857857
StringRef Name, StringRef IncludePath,
858+
StringRef CompDir,
858859
uint64_t Signature = ~1ULL,
859860
StringRef ASTFile = StringRef()) {
860861
// Look in the cache first.
@@ -864,6 +865,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
864865

865866
std::string RemappedIncludePath = DebugPrefixMap.remapPath(IncludePath);
866867
std::string RemappedASTFile = DebugPrefixMap.remapPath(ASTFile);
868+
std::string RemappedCompDir = DebugPrefixMap.remapPath(CompDir);
867869

868870
// For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
869871
if (!Opts.DisableClangModuleSkeletonCUs) {
@@ -873,7 +875,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
873875
llvm::DIBuilder DIB(M);
874876
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
875877
: llvm::dwarf::DW_LANG_C99,
876-
DIB.createFile(Name, RemappedIncludePath),
878+
DIB.createFile(Name, RemappedCompDir),
877879
TheCU->getProducer(), true, StringRef(), 0,
878880
RemappedASTFile, llvm::DICompileUnit::FullDebug,
879881
Signature);
@@ -900,12 +902,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
900902
uint64_t Signature =
901903
Desc.getSignature() ? Desc.getSignature().truncatedValue() : ~1ULL;
902904

903-
// Clang modules using fmodule-file-home-is-cwd should have their
904-
// include path set to the working directory.
905-
auto &HSI =
906-
CI.getClangPreprocessor().getHeaderSearchInfo().getHeaderSearchOpts();
907-
StringRef IncludePath =
908-
HSI.ModuleFileHomeIsCwd ? Opts.DebugCompilationDir : Desc.getPath();
905+
StringRef CompDir = Opts.DebugCompilationDir;
906+
StringRef IncludePath = Desc.getPath();
909907

910908
// Handle Clang modules.
911909
if (ClangModule) {
@@ -927,12 +925,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
927925
ClangModule->Parent);
928926
}
929927
return getOrCreateModule(ClangModule, Parent, Desc.getModuleName(),
930-
IncludePath, Signature, Desc.getASTFile());
928+
IncludePath, CompDir, Signature,
929+
Desc.getASTFile());
931930
}
932931
// Handle PCH.
933932
return getOrCreateModule(Desc.getASTFile().bytes_begin(), nullptr,
934-
Desc.getModuleName(), IncludePath, Signature,
935-
Desc.getASTFile());
933+
Desc.getModuleName(), IncludePath, CompDir,
934+
Signature, Desc.getASTFile());
936935
};
937936

938937
static std::optional<ASTSourceDescriptor>
@@ -955,7 +954,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
955954
// the module on disk is Bar (.swiftmodule or .swiftinterface), and is used
956955
// for loading and mangling.
957956
StringRef Name = M->getRealName().str();
958-
return getOrCreateModule(M, TheCU, Name, Path);
957+
return getOrCreateModule(M, TheCU, Name, Path, Opts.DebugCompilationDir);
959958
}
960959

961960
TypeAliasDecl *getMetadataType(StringRef ArchetypeName) {
@@ -2551,8 +2550,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25512550
auto Identifier = IGM.getSILModule().getASTContext().getIdentifier(
25522551
Attribute->ManglingModuleName);
25532552
void *Key = (void *)Identifier.get();
2554-
Scope =
2555-
getOrCreateModule(Key, TheCU, Attribute->ManglingModuleName, {});
2553+
Scope = getOrCreateModule(Key, TheCU, Attribute->ManglingModuleName, {},
2554+
{});
25562555
} else {
25572556
Context = ND->getParent();
25582557
}
@@ -2799,7 +2798,8 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
27992798
// Create a module for the current compile unit.
28002799
auto *MDecl = IGM.getSwiftModule();
28012800
llvm::sys::path::remove_filename(SourcePath);
2802-
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath);
2801+
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath,
2802+
Opts.DebugCompilationDir);
28032803
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
28042804

28052805
// Macro definitions that were defined by the user with "-Xcc -D" on the

test/DebugInfo/comp-dir.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module-path %t/Globals.swiftmodule %S/Globals.swift
3+
// RUN: %target-swift-frontend -c -I %t -primary-file %s -g -parse-as-library -emit-module -emit-object -module-cache-path "./mc" -file-compilation-dir "." -debug-prefix-map "$(pwd)=." -o %t/test.o
4+
// RUN: %llvm-dwarfdump %t/test.o | %FileCheck %s
5+
6+
// CHECK: DW_TAG_compile_unit
7+
8+
// CHECK: DW_TAG_compile_unit
9+
// CHECK-NOT: NULL
10+
// CHECK: DW_AT_comp_dir (".")
11+
// CHECK-NOT: NULL

0 commit comments

Comments
 (0)