[clang] a23a596 - [clang] Fix absolute file paths with -fdebug-prefix-map
Keith Smiley via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 8 10:35:29 PDT 2021
Author: Keith Smiley
Date: 2021-10-08T10:35:17-07:00
New Revision: a23a5967932292b82e9a7e4b37817d1b3f5be5ec
URL: https://github.com/llvm/llvm-project/commit/a23a5967932292b82e9a7e4b37817d1b3f5be5ec
DIFF: https://github.com/llvm/llvm-project/commit/a23a5967932292b82e9a7e4b37817d1b3f5be5ec.diff
LOG: [clang] Fix absolute file paths with -fdebug-prefix-map
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.
Differential Revision: https://reviews.llvm.org/D111352
Added:
clang/test/CodeGen/relative-debug-prefix-map.c
Modified:
clang/lib/CodeGen/CGDebugInfo.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 9c98278aa6221..42127d652e766 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -446,6 +446,9 @@ CGDebugInfo::createFile(StringRef FileName,
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
index 0000000000000..54fee97a83d0d
--- /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;
+}
More information about the cfe-commits
mailing list