| Issue |
185088
|
| Summary |
DW_AT_name for compile_unit incorrect when compiling preprocessed inputs with redundant slashes
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
akarle
|
## Overview
When compiling already preprocessed input files where the file path contains redundant slashes, the DW_AT_name in the DWARF data for the DW_TAG_compile_unit uses the preprocessed file name instead of the name from the line directive.
This appears unintentional, as relative paths and normalized absolute paths both use the line directive.
This was discovered when using distcc, which creates a temporary preprocessed file in $TMPDIR/distcc_XXX using a home-rolled mktemp function. If $TMPDIR has a slash at the end (as is the case on macOS), the path has redundant slashes and triggers the bug.
It's possible the bug exists in this code chunk in the comparison of file names, but I haven't attempted a fix yet:
https://github.com/llvm/llvm-project/blob/56569270b5f2deeadb568649ea1bf7fa1b3afcb0/clang/lib/CodeGen/CGDebugInfo.cpp#L796
## Minimal Reproduction
```
$ echo 'int foo() { return 42; }' > foo.c
$ clang -E foo.c > /tmp/x.i
$ clang -g -c /tmp/x.i -o good.o
$ clang -g -c /tmp//x.i -o bad.o
$ clang -g -c /tmp/../tmp/x.i -o rel.o
# redundant path is bad
$ dwarfdump bad.o
...
COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000c> DW_TAG_compile_unit
DW_AT_producer (indexed string: 0x00000000)clang version 21.1.1
DW_AT_language DW_LANG_C11
DW_AT_name (indexed string: 0x00000001)/tmp/x.i
...
# abs path is good
$ dwarfdump good.o
...
COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000c> DW_TAG_compile_unit
DW_AT_producer (indexed string: 0x00000000)clang version 21.1.1
DW_AT_language DW_LANG_C11
DW_AT_name (indexed string: 0x00000001)foo.c
...
# relative paths also OK
$ dwarfdump rel.o
...
COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000c> DW_TAG_compile_unit
DW_AT_producer (indexed string: 0x00000000)clang version 21.1.1
DW_AT_language DW_LANG_C11
DW_AT_name (indexed string: 0x00000001)foo.c
```
## Version Info
I can reproduce on Debian 12.13 using a build of clang 21.1.1:
```
$ clang --version
clang version 21.1.1
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
I an also reproduce it on a macOS machine with clang 16.0.0:
```
$ sw_vers
ProductName: macOS
ProductVersion: 15.3.1
BuildVersion: 24D70
$ cc --version
Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Applications/Xcode16.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
Thank you for your time and help!
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs