Open llvmbot opened 5 years ago
The assembly output looks like this for me with r358161:
main: # @main .Lfunc_begin0: .loc 1 2 0 # pr41548.c:2:0 .cfi_startproc
#DEBUG_VALUE: main:l_2849 <- 38358926
.loc 1 4 7 prologue_end # pr41548.c:4:7
cmpw $0, a(%rip)
.Ltmp0: .loc 1 4 7 is_stmt 0 # pr41548.c:4:7 je .LBB0_1
.Ltmp1:
.loc 1 9 1 is_stmt 1 # pr41548.c:9:1
xorl %eax, %eax
retq
.LBB0_1: # %if.else pushq %rax .cfi_def_cfa_offset 16 .Ltmp2: .loc 1 7 5 # pr41548.c:7:5 xorl %eax, %eax callq optimize_me_not addq $8, %rsp .cfi_def_cfa_offset 8 .Ltmp3:
.loc 1 9 1 # pr41548.c:9:1
xorl %eax, %eax
retq
And the location list entry:
.Ldebug_loc0: .quad .Lfunc_begin0-.Lfunc_begin0 .quad .Ltmp1-.Lfunc_begin0 .short 6 # Loc expr size .byte 17 # DW_OP_consts .byte 142 # 38358926 .byte 159 # .byte 165 # .byte 18 # .byte 159 # DW_OP_stack_value .quad .Ltmp1-.Lfunc_begin0 .quad .Lfunc_end0-.Lfunc_begin0 .short 3 # Loc expr size .byte 17 # DW_OP_consts .byte 0 # 0 .byte 159 # DW_OP_stack_value .quad 0 .quad 0
As seen, the zero-valued debug value that is located in the early return block continues to live on in the basic block where the call is made. Without verifying it, this looks like a case that is solved by Jeremy Morse's https://reviews.llvm.org/D59431.
Extended Description
This problem also happens under O2 and O3.
$ clang-trunk --version clang version 9.0.0 (trunk 355785) Target: x86_64-unknown-linux-gnu Thread model: posix
$ lldb-trunk --version lldb version 9.0.0 (https://llvm.org/svn/llvm-project/lldb/trunk revision 355785) clang revision 355785 llvm revision 355785
$ cat abc.c short a; int main() { int l_2849 = 38358926; if (a) ; else optimize_me_not(); l_2849 = 0; }
$ cat outer.c optimize_me_not() {}
$ clang-trunk -O0 -g abc.c outer.c
$ lldb-trunk -s cmds -b a.out (lldb) target create "a.out" Current executable set to 'a.out' (x86_64). (lldb) command source -s 0 'cmds' Executing commands in '/home/ybli/Projects/LLDB-testing/reduce.llvm/cmds'. (lldb) b 7 Breakpoint 1: where = a.out`main + 42 at abc.c:7:5, address = 0x00000000004004aa (lldb) r Process 30735 stopped
Process 30735 launched: '/home/ybli/Projects/LLDB-testing/reduce.llvm/a.out' (x86_64) (lldb) p l_2849 (int) $0 = 38358926 (lldb) kill Process 30735 exited with status = 9 (0x00000009) (lldb) q
$ clang-trunk -O1 -g abc.c outer.c
$ lldb-trunk -s cmds -b a.out (lldb) target create "a.out" Current executable set to 'a.out' (x86_64). (lldb) command source -s 0 'cmds' Executing commands in '/home/ybli/Projects/LLDB-testing/reduce.llvm/cmds'. (lldb) b 7 Breakpoint 1: where = a.out`main + 14 at abc.c:7:5, address = 0x000000000040048e (lldb) r Process 6641 stopped
Process 6641 launched: '/home/ybli/Projects/LLDB-testing/reduce.llvm/a.out' (x86_64) (lldb) p l_2849 (int) $0 = 0 (lldb) kill Process 6641 exited with status = 9 (0x00000009) (lldb) q
Pass bisection suggests that the problem is related to LEA fixup:
Correct case: BISECT: running pass (92) X86 Atom pad short functions on function (optimize_me_not) BISECT: NOT running pass (93) X86 LEA Fixup on function (optimize_me_not)
Incorrect case: BISECT: running pass (92) X86 Atom pad short functions on function (optimize_me_not) BISECT: running pass (93) X86 LEA Fixup on function (optimize_me_not)