diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -443,6 +443,9 @@ Dir = DirBuf; File = FileBuf; } + } else if (llvm::sys::path::is_absolute(FileName)) { + Dir = llvm::sys::path::parent_path(RemappedFile); + File = llvm::sys::path::filename(RemappedFile); } else { Dir = CurDir; File = RemappedFile; diff --git a/clang/test/CodeGen/relative-debug-prefix-map.c b/clang/test/CodeGen/relative-debug-prefix-map.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/relative-debug-prefix-map.c @@ -0,0 +1,17 @@ +// RUN: mkdir -p %t.nested/dir && cd %t.nested/dir +// RUN: cp %s %t.nested/dir/main.c +// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%t.nested=. %t.nested/dir/main.c -emit-llvm -o - | FileCheck %s +// +// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=. %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-DIRECT +// +// RUN: cd %p +// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-compilation-dir=. relative-debug-prefix-map.c -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-DIRECT + +// CHECK: !DIFile(filename: "main.c", directory: "./dir") +// CHECK-DIRECT: !DIFile(filename: "relative-debug-prefix-map.c", directory: ".") + +int main(int argc, char **argv) { + (void)argc; + (void)argv; + return 0; +} diff --git a/clang/test/Modules/module-debuginfo-prefix.m b/clang/test/Modules/module-debuginfo-prefix.m --- a/clang/test/Modules/module-debuginfo-prefix.m +++ b/clang/test/Modules/module-debuginfo-prefix.m @@ -4,23 +4,21 @@ // Modules: // RUN: rm -rf %t // RUN: %clang_cc1 -x objective-c -fmodules -fmodule-format=obj \ -// RUN: -fdebug-prefix-map=%S/Inputs=/OVERRIDE \ +// RUN: -fdebug-prefix-map=%S%{fssep}Inputs=%{fssrcroot}OVERRIDE \ // RUN: -fimplicit-module-maps -DMODULES -fmodules-cache-path=%t %s \ // RUN: -I %S/Inputs -I %t -emit-llvm -o %t.ll \ // RUN: -mllvm -debug-only=pchcontainer &>%t-mod.ll -// RUN: cat %t-mod.ll | FileCheck %s +// RUN: cat %t-mod.ll | FileCheck %s -DROOT=%{fssrcroot} -DSEP=%{fssep} // PCH: // RUN: %clang_cc1 -x objective-c -emit-pch -fmodule-format=obj -I %S/Inputs \ -// RUN: -fdebug-prefix-map=%S/Inputs=/OVERRIDE \ +// RUN: -fdebug-prefix-map=%S%{fssep}Inputs=%{fssrcroot}OVERRIDE \ // RUN: -o %t.pch %S/Inputs/DebugObjC.h \ // RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll -// RUN: cat %t-pch.ll | FileCheck %s +// RUN: cat %t-pch.ll | FileCheck %s -DROOT=%{fssrcroot} -DSEP=%{fssep} #ifdef MODULES @import DebugObjC; #endif -// Dir should always be empty, but on Windows we can't recognize /var -// as being an absolute path. -// CHECK: !DIFile(filename: "/OVERRIDE/DebugObjC.h", directory: "{{()|(.*:.*)}}") +// CHECK: !DIFile(filename: "[[ROOT]]OVERRIDE[[SEP]]DebugObjC.h", directory: "")