Skip to content

Commit 2cd9a86

Browse files
committed
Don't append the working directory to absolute paths
This fixes a bug that happens when using -fdebug-prefix-map to remap an absolute path to a relative path. Since the path was absolute before remapping, it is safe to assume that concatenating the remapped working directory would be wrong. Differential Revision: https://reviews.llvm.org/D113718
1 parent c05da55 commit 2cd9a86

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ CGDebugInfo::createFile(StringRef FileName,
444444
File = FileBuf;
445445
}
446446
} else {
447-
Dir = CurDir;
447+
if (!llvm::sys::path::is_absolute(FileName))
448+
Dir = CurDir;
448449
File = RemappedFile;
449450
}
450451
llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);

clang/test/CodeGen/debug-prefix-map.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -isysroot %p -debugger-tuning=lldb | FileCheck %s -check-prefix CHECK-SYSROOT
66
// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
77
// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
8+
// RUN: %clang -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
9+
// RUN: %clang -g -ffile-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
810

911
#include "Inputs/stdio.h"
1012

@@ -42,3 +44,7 @@ void test_rewrite_includes(void) {
4244
// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs/stdio.h", directory: "/UNLIKELY_PATH/empty")
4345
// CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
4446
// CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "/UNLIKELY_PATH/empty"
47+
48+
// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}",
49+
// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}Inputs/stdio.h",
50+
// CHECK-REL-SAME: directory: "")

0 commit comments

Comments
 (0)