[PATCH] D111587: re-land: [clang] Fix absolute file paths with -fdebug-prefix-map
Keith Smiley via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 11 17:01:33 PDT 2021
keith created this revision.
keith added a reviewer: probinson.
keith requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Previously if you passed an absolute path to clang, where only part of
the path to the file was remapped, it would result in the file's DIFile
being stored with a duplicate path, for example:
!DIFile(filename: "./ios/Sources/bar.c", directory: "./ios/Sources")
This change handles absolute paths, specifically in the case they are
remapped to something relative, and uses the dirname for the directory,
and basename for the filename.
This also adds a test verifying this behavior for more standard uses as
well.
This reverts commit 68e49aea9ac4dca550df70706cc845de04939c03 <https://reviews.llvm.org/rG68e49aea9ac4dca550df70706cc845de04939c03>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D111587
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
clang/test/CodeGen/relative-debug-prefix-map.c
clang/test/Modules/module-debuginfo-prefix.m
Index: clang/test/Modules/module-debuginfo-prefix.m
===================================================================
--- clang/test/Modules/module-debuginfo-prefix.m
+++ clang/test/Modules/module-debuginfo-prefix.m
@@ -3,7 +3,7 @@
// 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%{sep}Inputs=%{rootsep}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
@@ -11,7 +11,7 @@
// 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%{sep}Inputs=%{rootsep}OVERRIDE \
// RUN: -o %t.pch %S/Inputs/DebugObjC.h \
// RUN: -mllvm -debug-only=pchcontainer &>%t-pch.ll
// RUN: cat %t-pch.ll | FileCheck %s
@@ -20,6 +20,4 @@
@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: "{{/|C:\\\\}}OVERRIDE{{/|\\\\}}DebugObjC.h", directory: "")
Index: clang/test/CodeGen/relative-debug-prefix-map.c
===================================================================
--- /dev/null
+++ 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;
+}
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -446,6 +446,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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111587.378829.patch
Type: text/x-patch
Size: 2763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211012/9aa621b7/attachment-0001.bin>
More information about the cfe-commits
mailing list