Skip to content

Commit

Permalink
Allow remapping Clang module skeleton CU references with -fdebug-pref…
Browse files Browse the repository at this point in the history
…ix-map

Differential Revision: https://reviews.llvm.org/D76383

(cherry picked from commit 43580a5)
  • Loading branch information
adrian-prantl committed Apr 9, 2020
1 parent cff98e9 commit 2e1899c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
10 changes: 7 additions & 3 deletions clang/lib/CodeGen/CGDebugInfo.cpp
Expand Up @@ -2456,14 +2456,18 @@ CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
: ~1ULL;
llvm::DIBuilder DIB(CGM.getModule());
SmallString<0> PCM;
if (!llvm::sys::path::is_absolute(PCM))
if (!llvm::sys::path::is_absolute(Mod.getASTFile()))
PCM = Mod.getPath();
llvm::sys::path::append(PCM, Mod.getASTFile());
StringRef CompDir = getCurrentDirname();
std::string RemappedPCM = remapDIPath(PCM);
StringRef RelativePCM(RemappedPCM);
StringRef CompDir = TheCU->getDirectory();
if (RelativePCM.consume_front(CompDir))
RelativePCM.consume_front(llvm::sys::path::get_separator());
DIB.createCompileUnit(TheCU->getSourceLanguage(),
// TODO: Support "Source" from external AST providers?
DIB.createFile(Mod.getModuleName(), CompDir),
TheCU->getProducer(), false, StringRef(), 0, PCM,
TheCU->getProducer(), false, StringRef(), 0, RelativePCM,
llvm::DICompileUnit::FullDebug, Signature);
DIB.finalize();
}
Expand Down
23 changes: 16 additions & 7 deletions clang/test/Modules/debug-info-moduleimport.m
@@ -1,11 +1,19 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - | FileCheck %s --check-prefix=NOIMPORT
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
// RUN: -DGREETING="Hello World" -UNDEBUG \
// RUN: -fimplicit-module-maps -fmodules-cache-path=%t %s \
// RUN: -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
// RUN: | FileCheck %s --check-prefix=NOIMPORT

// NOIMPORT-NOT: !DIImportedEntity
// NOIMPORT-NOT: !DIModule

// RUN: rm -rf %t
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -DGREETING="Hello World" -UNDEBUG -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -debugger-tuning=lldb -o - | FileCheck %s
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules \
// RUN: -DGREETING="Hello World" -UNDEBUG \
// RUN: -fimplicit-module-maps -fmodules-cache-path=%t %s \
// RUN: -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm \
// RUN: -debugger-tuning=lldb -o - | FileCheck %s

// CHECK: ![[CU:.*]] = distinct !DICompileUnit
// CHECK-SAME: sysroot: "/tmp/..")
Expand All @@ -18,17 +26,18 @@
// CHECK-SAME: includePath: "{{.*}}test{{.*}}Modules{{.*}}Inputs"
// CHECK: ![[F]] = !DIFile(filename: {{.*}}debug-info-moduleimport.m

// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
// RUN: %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
// RUN: | FileCheck %s --check-prefix=NO-SKEL-CHECK
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
// RUN: -fmodules-cache-path=%t %s -I %S/Inputs -isysroot /tmp/.. -I %t \
// RUN: -emit-llvm -o - | FileCheck %s --check-prefix=NO-SKEL-CHECK
// NO-SKEL-CHECK: distinct !DICompileUnit
// NO-SKEL-CHECK-NOT: distinct !DICompileUnit

// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps -fmodules-cache-path=%t \
// RUN: %clang_cc1 -debug-info-kind=limited -fmodules -fimplicit-module-maps \
// RUN: -fmodules-cache-path=%t -fdebug-prefix-map=%t=/MODULE-CACHE \
// RUN: -fmodule-format=obj -dwarf-ext-refs \
// RUN: %s -I %S/Inputs -isysroot /tmp/.. -I %t -emit-llvm -o - \
// RUN: | FileCheck %s --check-prefix=SKEL-CHECK
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[CUFILE:[0-9]+]]
// SKEL-CHECK: ![[CUFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR:.*]]"
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}dwoId
// SKEL-CHECK: distinct !DICompileUnit({{.*}}file: ![[DWOFILE:[0-9]+]]{{.*}}splitDebugFilename: "/MODULE-CACHE{{.*}}dwoId
// SKEL-CHECK: ![[DWOFILE]] = !DIFile({{.*}}directory: "[[COMP_DIR]]"
6 changes: 3 additions & 3 deletions clang/test/PCH/debug-info-pch-path.c
Expand Up @@ -23,7 +23,7 @@
// CHECK-REL-NODIR: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-REL-NODIR: !DICompileUnit(
// CHECK-REL-NODIR-SAME: file: ![[PCH:[0-9]+]]
// CHECK-REL-NODIR-SAME: splitDebugFilename: "{{.*}}PCH{{.*}}prefix.pch"
// CHECK-REL-NODIR-SAME: splitDebugFilename: "prefix.pch"
// CHECK-REL-NODIR: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]

// ---------------------------------------------------------------------
Expand All @@ -47,7 +47,7 @@
// CHECK-REL: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-REL: !DICompileUnit(
// CHECK-REL-SAME: file: ![[PCH:[0-9]+]]
// CHECK-REL-SAME: splitDebugFilename: "[[DIR]]{{.*}}pchdir{{.*}}prefix.pch"
// CHECK-REL-SAME: splitDebugFilename: "pchdir{{.*}}prefix.pch"
// CHECK-REL: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]"

// ---------------------------------------------------------------------
Expand All @@ -70,5 +70,5 @@
// CHECK-ABS: ![[C]] = !DIFile({{.*}}directory: "[[DIR:.*]]"
// CHECK-ABS: !DICompileUnit(
// CHECK-ABS-SAME: file: ![[PCH:[0-9]+]]
// CHECK-ABS-SAME: splitDebugFilename: "[[DIR]]{{.*}}prefix.pch"
// CHECK-ABS-SAME: splitDebugFilename: "prefix.pch"
// CHECK-ABS: ![[PCH]] = !DIFile({{.*}}directory: "[[DIR]]

0 comments on commit 2e1899c

Please sign in to comment.