From 2cd9a86da54f8be4eb2aff3e766b125cbdeb023f Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 25 Feb 2022 11:38:16 -0800 Subject: [PATCH] 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 --- clang/lib/CodeGen/CGDebugInfo.cpp | 3 ++- clang/test/CodeGen/debug-prefix-map.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 2203f0a..28d318c 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 1c5d3a6..2241b70 100644 --- a/clang/test/CodeGen/debug-prefix-map.c +++ b/clang/test/CodeGen/debug-prefix-map.c @@ -5,6 +5,8 @@ // 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 // RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s // RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/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" @@ -42,3 +44,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: "") -- 2.7.4