Open noxwell opened 8 months ago
@llvm/issue-subscribers-clang-codegen
Author: Aleksei Vetrov (noxwell)
@llvm/issue-subscribers-debuginfo
Author: Aleksei Vetrov (noxwell)
A test may look like this:
// 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: )
Description
DWARF file entry consists of filename and directory. When
filename
is relative, it is relative to thedirectory
, but whenfilename
is absolute,directory
should be empty. However, after being transformed throughCGDebugInfo::remapDIPath
, absolutefilename
may become relative, which leads to a bug, that it becomes relative to the current working directory, and the resulting DWARF file location points to a file that doesn't exist.Steps to reproduce
Expected output
Actual output
How to fix
This case is already handled in
CGDebugInfo::createFile
. ButCGDebugInfo::CreateCompileUnit
usesDBuilder.createFile
directly instead of callingCGDebugInfo::createFile
wrapper, which leads to incorrect file entry.