[clang] [Clang][DebugInfo] Use CGDebugInfo::createFile in CGDebugInfo::CreateCompileUnit (#83174) (PR #83175)

Aleksei Vetrov via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 28 09:10:26 PST 2024


https://github.com/noxwell updated https://github.com/llvm/llvm-project/pull/83175

>From 731463e1134b0821e518a3e8e521a2d44dd18a8e Mon Sep 17 00:00:00 2001
From: Aleksei Vetrov <vvvvvv at google.com>
Date: Tue, 27 Feb 2024 19:50:13 +0000
Subject: [PATCH] [Clang][DebugInfo] Use CGDebugInfo::createFile in
 CGDebugInfo::CreateCompileUnit

Use `CGDebugInfo::createFile` wrapper that handles file remapping and
corner cases instead of directly using `DBuilder.createFile` in
`CGDebugInfo::CreateCompileUnit`.

Add test to check corner case with remapping absolute path to relative.

Fixes #83174
---
 clang/lib/CodeGen/CGDebugInfo.cpp             |  5 ++---
 clang/test/CodeGen/debug-info-abspath-remap.c | 20 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/debug-info-abspath-remap.c

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index c2c01439f2dc99..22cb3492ebe11a 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -628,9 +628,8 @@ void CGDebugInfo::CreateCompileUnit() {
   // file was specified with an absolute path.
   if (CSKind)
     CSInfo.emplace(*CSKind, Checksum);
-  llvm::DIFile *CUFile = DBuilder.createFile(
-      remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
-      getSource(SM, SM.getMainFileID()));
+  llvm::DIFile *CUFile =
+      createFile(MainFileName, CSInfo, getSource(SM, SM.getMainFileID()));
 
   StringRef Sysroot, SDK;
   if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
diff --git a/clang/test/CodeGen/debug-info-abspath-remap.c b/clang/test/CodeGen/debug-info-abspath-remap.c
new file mode 100644
index 00000000000000..9a4f146c3254f9
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-abspath-remap.c
@@ -0,0 +1,20 @@
+// RUN: mkdir -p %t/src
+// RUN: cp %s %t/src/debug-info-debug-prefix-map.c
+
+// RUN: mkdir -p %t/out
+// RUN: cd %t/out
+// RUN: %clang_cc1 -debug-info-kind=limited -triple %itanium_abi_triple \
+// RUN:   -fdebug-prefix-map="%t/=./" %t/src/debug-info-debug-prefix-map.c \
+// RUN:   -emit-llvm -o - | FileCheck %s
+
+void foo(void) {}
+
+// Compile unit filename is transformed from absolute path %t/src... to
+// a relative path ./src... But it should not be relative to directory "./out".
+
+// CHECK: = distinct !DICompileUnit({{.*}}file: ![[#CUFILE:]]
+// CHECK: ![[#CUFILE]] = !DIFile(
+// CHECK-NOT:    directory: "./out"
+// CHECK-SAME:   filename: "./src{{[^"]+}}"
+// CHECK-NOT:    directory: "./out"
+// CHECK-SAME: )



More information about the cfe-commits mailing list