[LLVMdev] Why variables get "optimized away" after the last use in unoptimized code?

Yuri yuri at rawbw.com
Sun Feb 2 01:11:25 PST 2014


I am seeing this with llvm generated code, and before also saw this with 
gcc generated code.
In unoptimized code, debugger would say something like this when the 
variable isn't used any more, but is still in scope:
(gdb) p this
$11 = <optimized out>

Looking at the debug records, I don't see what is wrong, for example:
   call void @llvm.dbg.declare(metadata !{%struct.Object* %1}, metadata 
!73), !dbg !74
!73 = metadata !{i32 786689, metadata !63, metadata !"this", metadata 
!68, i32 33554949, metadata !12, i32 0, i32 0} ; [ DW_TAG_arg_variable ] 
[this] [line 517]
!63 is DW_TAG_subprogram scope.

'this' should exist through this subprogram, and never disappear. But it 
becomes "optimized away" after the last explicit use. Same is true with 
any other variable.
Doesn't this mean that llvm generates wrong DWARF info?
I don't think that debugger should ever say <optimized out> in 
unoptimized code.

Yuri



More information about the llvm-dev mailing list