Open cristianassaiante opened 2 years ago
@llvm/issue-subscribers-debuginfo
I'd guess an early transformation removes the read for l_47 entirely, since it's dead - then later on the read for b[e] is emitted.
I don't think it's practical/likely that l_47 will have a location in this code if it's optimized at all - even the most basic optimization would remove the read of the global.
"becomes available with its correct value at line 10." - oh, that is interesting. Sorry, missed that - I'm surprised it's preserved at all. Maybe there's some chance this could be made to work, then.
In this minimized C example, the pointer variable
l_47
, assigned at line 6 in the inner scope {} inside the main function, is marked as not available at line 9 and becomes available with its correct value at line 10.Apparently this behavior is caused by SROA. By debugging and analyzing the DWARF with opt-bisect-limit, after SROA there is no longer a DW_AT_location for the variable and the value goes away.
SimplifyCFG eventually adds the location, but only for addresses associated with line 10. Looking at the assembly, line 9 ends up being associated with the
&a
operation done both at line 6 and line 9 in the source program. Perhaps, line 9 could go with the next assembly instruction or even the movdqa operations that assignb[e]
?The issue happens when the optimization level is Os. With Og/O1/O2/O3 the variable is optimized out.
We tested clang and lldb 14.0.0 commit 116dc70 on x64.
LLDB trace:
ASM at -Os:
DWARF info at -Os:
The location range for
l_47
does not include the instruction at401108
, which in the line number table is associated with line 9, while line 10 goes with the instruction at401127
. In turn,401108
reads the address of variable a, which is used both to assignl_47
at line 6 and thenb[e]
at line 9. Perhaps line 6 should go with401108
and line 9 with a later one?DWARF before SROA at -Os:
DWARF after SROA at -Os:
SimplifyCFG eventually adds range information.
DWARF info at -Os before SimplifyCFG:
After SimplifyCFG, the DWARF is identical to the one reported above for -Os.