Skip to content

Commit 122e7af

Browse files
committed
PCH debug info: Avoid appending the source directory to an absolute path
When building a precompiled header in -fmodule-format=obj (i.e., `-gmodules) in an absolute path, the locig in CGDebugInfo::createCompileUnit would unconditionally append the source directory to the -main-file-name. This patch avoids that behavior for absolute paths. rdar://problem/46045865 Differential Revision: https://reviews.llvm.org/D69213 llvm-svn: 375423
1 parent 7a79e10 commit 122e7af

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,11 @@ void CGDebugInfo::CreateCompileUnit() {
539539
// file to determine the real absolute path for the file.
540540
std::string MainFileDir;
541541
if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
542-
MainFileDir = remapDIPath(MainFile->getDir()->getName());
543-
if (MainFileDir != ".") {
542+
MainFileDir = MainFile->getDir()->getName();
543+
if (!llvm::sys::path::is_absolute(MainFileName)) {
544544
llvm::SmallString<1024> MainFileDirSS(MainFileDir);
545545
llvm::sys::path::append(MainFileDirSS, MainFileName);
546-
MainFileName = MainFileDirSS.str();
546+
MainFileName = llvm::sys::path::remove_leading_dotslash(MainFileDirSS);
547547
}
548548
// If the main file name provided is identical to the input file name, and
549549
// if the input file is a preprocessed source, use the module name for
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// REQUIRES: asserts
2+
3+
// Modules:
4+
// RUN: rm -rf %t
5+
// RUN: mkdir %t
6+
// RUN: cd %t
7+
8+
// RUN: %clang_cc1 -fmodule-format=obj -emit-pch \
9+
// RUN: -triple %itanium_abi_triple \
10+
// RUN: -fdebug-prefix-map=%t=BUILD \
11+
// RUN: -fdebug-prefix-map=%S=SOURCE \
12+
// RUN: -o %t/prefix.ll %S/debug-info-limited-struct.h \
13+
// RUN: -mllvm -debug-only=pchcontainer &>%t-container.ll
14+
// RUN: cat %t-container.ll | FileCheck %s
15+
16+
// CHECK: distinct !DICompileUnit(
17+
// CHECK-SAME: language: DW_LANG_C99,
18+
// CHECK-SAME: file: ![[FILE:[0-9]+]],
19+
// CHECK: ![[FILE]] = !DIFile(
20+
// CHECK-SAME: filename: "SOURCE/debug-info-limited-struct.h",
21+
// CHECK-SAME: directory: "BUILD"
22+

0 commit comments

Comments
 (0)