Line 0 emission unexpectedly skipped when files change
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
It is possible to have successive machine instructions at the MIR level which each have a debug location of line 0, but for different files, as in the example below (edited for readability):
```llvm
bb.8.handler.type_mismatch12:
liveins: $rsi
$edi = MOV32ri @6, implicit-def $rdi, debug-location !DILocation(line: 0, scope: !52, inlinedAt: !55) /* b.c:0 inlined in a.c */
bb.9.cleanup:
liveins: $rdi, $rsi
CALL64pcrel32 target-flags(x86-plt) @__ubsan_handle_type_mismatch_v1, /* ... */, debug-location !DILocation(line: 0, scope: !33) /* a.c:0 */
```
At the moment however, LLVM DWARF emission skips the second line 0 without considering the changed file:
https://github.com/llvm/llvm-project/blob/10f84995b430a7964d0873488100756a52652fa0/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L2267-L2271
This means the file change is lost. A debugger's backtrace and disassembly views would thus show the wrong file for the second instruction. This also affects other analysis tools (e.g. sanitisers like UBSan in the example above) that wish to report a stack trace for failure locations, as they will currently cite the wrong file.
Contributor guide
Assessment
This issue has not been assessed yet.