Skip to content

Commit a2db7d5

Browse files
committed
reland: [clang] 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. This was originally submitted as https://reviews.llvm.org/D113718, but reverted because when testing with dwarf 5 enabled, the tests were too strict. Differential Revision: https://reviews.llvm.org/D121663
1 parent 1db8112 commit a2db7d5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

+2-1
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

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
// RUN: %clang -g -fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
77
// RUN: %clang -g -ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
88

9+
// RUN: %clang -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
10+
// RUN: %clang -g -ffile-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
11+
912
#include "Inputs/stdio.h"
1013

1114
int main(int argc, char **argv) {
@@ -40,3 +43,7 @@ void test_rewrite_includes(void) {
4043
// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs{{/|\\\\}}stdio.h", directory: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty")
4144
// CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
4245
// CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty"
46+
47+
// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}",
48+
// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}Inputs/stdio.h",
49+
// CHECK-REL-SAME: directory: ""

0 commit comments

Comments
 (0)