https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105024
Bug ID: 105024 Summary: g++ generates wrong line debug information Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: blarsen at redhat dot com Target Milestone: --- Created attachment 52665 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52665&action=edit minimal testcase When compiling the attached test case with the options -g -O0, there is a bug in the line table generation. The first instruction of merge_sort is assigned to line 17 instead of line 2, then backtracks to line 5. It generates some confusion when trying to debug the code, as GDB prints the wrong line when that instruction is being evaluated. My guess is that g++ sees the early exit and assumes that part of the "if" is related to that exit, and mislabels that instruction. I tried removing the "return" statement and putting the rest of the code inside an else block, and the line table was closer to what I expected. This seems to be a long standing bug, as I can reproduce it with g++ 8.5.0 and g++ 11.2.1, though 8.5.0 sets the line as 16 instead.