Skip to content

Commit b286b1c

Browse files
Set the Compilation directory when generating the Skeleton CU
When creating a skeleton Compile Unit, the DIFile passed in, it always uses the include path. This leads to the DW_AT_comp_dir being wrong, if the -file-compilation-dir option is passed, we need to use the remapped compilation dir passed in to the DIFile instead. This patch fixes that problem.
1 parent 80e8d3a commit b286b1c

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
@@ -847,6 +847,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
847847

848848
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
849849
StringRef Name, StringRef IncludePath,
850+
StringRef CompDir,
850851
uint64_t Signature = ~1ULL,
851852
StringRef ASTFile = StringRef()) {
852853
// Look in the cache first.
@@ -856,6 +857,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
856857

857858
std::string RemappedIncludePath = DebugPrefixMap.remapPath(IncludePath);
858859
std::string RemappedASTFile = DebugPrefixMap.remapPath(ASTFile);
860+
std::string RemappedCompDir = DebugPrefixMap.remapPath(CompDir);
859861

860862
// For Clang modules / PCH, create a Skeleton CU pointing to the PCM/PCH.
861863
if (!Opts.DisableClangModuleSkeletonCUs) {
@@ -865,7 +867,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
865867
llvm::DIBuilder DIB(M);
866868
DIB.createCompileUnit(IGM.ObjCInterop ? llvm::dwarf::DW_LANG_ObjC
867869
: llvm::dwarf::DW_LANG_C99,
868-
DIB.createFile(Name, RemappedIncludePath),
870+
DIB.createFile(Name, RemappedCompDir),
869871
TheCU->getProducer(), true, StringRef(), 0,
870872
RemappedASTFile, llvm::DICompileUnit::FullDebug,
871873
Signature);
@@ -892,12 +894,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
892894
uint64_t Signature =
893895
Desc.getSignature() ? Desc.getSignature().truncatedValue() : ~1ULL;
894896

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();
897+
StringRef CompDir = Opts.DebugCompilationDir;
898+
StringRef IncludePath = Desc.getPath();
901899

902900
// Handle Clang modules.
903901
if (ClangModule) {
@@ -919,12 +917,13 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
919917
ClangModule->Parent);
920918
}
921919
return getOrCreateModule(ClangModule, Parent, Desc.getModuleName(),
922-
IncludePath, Signature, Desc.getASTFile());
920+
IncludePath, CompDir, Signature,
921+
Desc.getASTFile());
923922
}
924923
// Handle PCH.
925924
return getOrCreateModule(Desc.getASTFile().bytes_begin(), nullptr,
926-
Desc.getModuleName(), IncludePath, Signature,
927-
Desc.getASTFile());
925+
Desc.getModuleName(), IncludePath, CompDir,
926+
Signature, Desc.getASTFile());
928927
};
929928

930929
static std::optional<ASTSourceDescriptor>
@@ -947,7 +946,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
947946
// the module on disk is Bar (.swiftmodule or .swiftinterface), and is used
948947
// for loading and mangling.
949948
StringRef Name = M->getRealName().str();
950-
return getOrCreateModule(M, TheCU, Name, Path);
949+
return getOrCreateModule(M, TheCU, Name, Path, Opts.DebugCompilationDir);
951950
}
952951

953952
TypeAliasDecl *getMetadataType(StringRef ArchetypeName) {
@@ -2543,8 +2542,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
25432542
auto Identifier = IGM.getSILModule().getASTContext().getIdentifier(
25442543
Attribute->ManglingModuleName);
25452544
void *Key = (void *)Identifier.get();
2546-
Scope =
2547-
getOrCreateModule(Key, TheCU, Attribute->ManglingModuleName, {});
2545+
Scope = getOrCreateModule(Key, TheCU, Attribute->ManglingModuleName, {},
2546+
{});
25482547
} else {
25492548
Context = ND->getParent();
25502549
}
@@ -2791,7 +2790,8 @@ IRGenDebugInfoImpl::IRGenDebugInfoImpl(const IRGenOptions &Opts,
27912790
// Create a module for the current compile unit.
27922791
auto *MDecl = IGM.getSwiftModule();
27932792
llvm::sys::path::remove_filename(SourcePath);
2794-
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath);
2793+
MainModule = getOrCreateModule(MDecl, TheCU, Opts.ModuleName, SourcePath,
2794+
Opts.DebugCompilationDir);
27952795
DBuilder.createImportedModule(MainFile, MainModule, MainFile, 0);
27962796

27972797
// 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)