http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55346
Bug #: 55346 Summary: var-tracking generates incomplete/inaccurate debug info Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: ea...@eagercon.com Created attachment 28703 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28703 Test program Var-tracking is does not record the lifetime of variables allocated to registers correctly, resulting in gdb displaying the variable as "optimized out" when it is live. I've confirmed this problem on x86 and arm. The test case is a loop which parses command line options, indexed by integer variable argno. When compiled with "-g -O2", argno is allocated to rbx, which is never reused. The DWARF location list which is generated from NOTE_INSN_VAR_LOCATION insns, shows disjoint allocations for argno, omitting PC ranges where the variable is live in rbx. The DWARF location list has argno as literal 1 beyond the instruction where it is allocated to rbx. Argno is defined as rbx starts several instructions after it is allocated and ends premature. Var-tracking inserts a NOTE_INSN_VAR_LOCATION for argno as const int 1 at the start of the BB #2, but one is not inserted when argno is allocated to rbx later in BB #2. One is generated later, in BB #5. Var-tracking inserts a (nil) NOTE_INSN_VAR_LOCATION for argno after BB #3 (branch to epilogue), although argno is live and is used in BB #4, immediately following BB #3. Either this should not be generated or another NOTE_INSN_VAR_LOCATION for argno should be generated at the start of BB #4.