[llvm] [DebugInfo] Don't set prologue_end behind line-zero call insts (PR #156850)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 17 05:59:10 PST 2025
jmorse wrote:
Thanks for the catch on which instruction position, this was a very sophisticated off-by-one,
> Perhaps someone could summarize in a comment (with examples of assembly/instructions - what data we have, what we did before, what we're doing now) what we're doing/why we're doing it?
Illustrating the test example, in very rare circumstances call instructions can have line-zero, when they get branch-folded together for example. In contrived code such as the below:
void ext();
int main(int argc, char **argv) {
if (argc == 1)
ext();
else
ext();
return 0;
}
The calls to `ext` will be hoisted+merged, and receive line zero. This can happen in non-contrived scenarios where call arguments get CSE'd, hoisted, speculated, or otherwise extracted out of the conditional blocks. It's popped up in some rare scenarios in the game codebases we have to hand. This produces assembly and line numbers like the below:
push %rax ; scope line for main
xor %eax,%eax ; empty DebugLoc, adopts scope-line for main,
call 8 <main+0x8> ; line zero
xor %eax,%eax ; return statement line number, prologue_end
pop %rcx
ret
Where the first few instructions have empty debug-locs because they're all compiler generated, and the call has line zero because its source locations have been merged. The only "legitimate" line number in the function is then the return statement, which is where todays LLVM places prologue_end. This then means that a debugger honouring prologue_end as the correct place to put a function-breakpoint, will break into a function already having executed the function call. Which is catastrophic for interactive debugging.
This patch is forcing the call instruction to have the function-scope line number, and putting prologue_end on that instruction too. It means we're bending the truth about the source location of the call instruction so that we can put the prologue_end somewhere meaningful. However, the alternative is no prologue_end at all, which is also poor.
https://github.com/llvm/llvm-project/pull/156850
More information about the llvm-commits
mailing list