[clang] a2db7d5 - reland: [clang] Don't append the working directory to absolute paths
Keith Smiley via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 15 13:42:44 PDT 2022
Author: Keith Smiley
Date: 2022-03-15T13:42:35-07:00
New Revision: a2db7d5e9c52804544363ea819de174bfaa7ecdd
URL: https://github.com/llvm/llvm-project/commit/a2db7d5e9c52804544363ea819de174bfaa7ecdd
DIFF: https://github.com/llvm/llvm-project/commit/a2db7d5e9c52804544363ea819de174bfaa7ecdd.diff
LOG: 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
Added:
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/debug-prefix-map.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 06501b34cbaef..0286d0e876f9d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -444,7 +444,8 @@ CGDebugInfo::createFile(StringRef FileName,
File = FileBuf;
}
} else {
- Dir = CurDir;
+ if (!llvm::sys::path::is_absolute(FileName))
+ Dir = CurDir;
File = RemappedFile;
}
llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
diff --git a/clang/test/CodeGen/debug-prefix-map.c b/clang/test/CodeGen/debug-prefix-map.c
index fb2c1d39a1522..f604f1643ba02 100644
--- a/clang/test/CodeGen/debug-prefix-map.c
+++ b/clang/test/CodeGen/debug-prefix-map.c
@@ -6,6 +6,9 @@
// RUN: %clang -g -fdebug-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
// RUN: %clang -g -ffile-prefix-map=%p=%{fs-src-root}UNLIKELY_PATH%{fs-sep}empty -S -c %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+// RUN: %clang -g -ffile-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
#include "Inputs/stdio.h"
int main(int argc, char **argv) {
@@ -40,3 +43,7 @@ void test_rewrite_includes(void) {
// CHECK-COMPILATION-DIR: !DIFile(filename: "{{.*}}Inputs{{/|\\\\}}stdio.h", directory: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty")
// CHECK-COMPILATION-DIR-NOT: !DIFile(filename:
// CHECK-SYSROOT: !DICompileUnit({{.*}}sysroot: "{{/|.:\\\\}}UNLIKELY_PATH{{/|\\\\}}empty"
+
+// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}",
+// CHECK-REL: !DIFile(filename: "./UNLIKELY_PATH/empty{{/|\\\\}}{{.*}}Inputs/stdio.h",
+// CHECK-REL-SAME: directory: ""
More information about the cfe-commits
mailing list