Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong debug info generated at -O3 (-O0 is correct) #43302

Closed
llvmbot opened this issue Nov 11, 2019 · 5 comments
Closed

Wrong debug info generated at -O3 (-O0 is correct) #43302

llvmbot opened this issue Nov 11, 2019 · 5 comments
Labels
bugzilla Issues migrated from bugzilla clang:codegen

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 11, 2019

Bugzilla Link 43957
Resolution FIXED
Resolved on Feb 13, 2020 07:34
Version trunk
OS Linux
Blocks #38116
Reporter LLVM Bugzilla Contributor
CC @adrian-prantl,@gregbedwell,@jmorse,@jdm,@OCHyams,@pogo59,@zygoloid,@rnk,@vedantk
Fixed by commit(s) 1e40799

Extended Description

The expected output from lldb should be 36902. However, compiled with "-O3", lldb outputs 36901.

$ clang-trunk -v
clang version 10.0.0 (trunk 375507)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64

$ clang-trunk -g abc.c -O3
$ lldb-trunk -s cmds -b a.out
(lldb) target create "a.out"
Current executable set to '/home/sding/LLDB-testing/reduce/30986/report/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/sding/LLDB-testing/reduce/30986/report/cmds'.
(lldb) b 6
Breakpoint 1: where = a.out`main + 10 at abc.c:6:7, address = 0x000000000040048a
(lldb) r
Process 10166 stopped

  • thread #​1, name = 'a.out', stop reason = breakpoint 1.1
    frame #​0: 0x000000000040048a a.out`main at abc.c:6:7
    3 --b;
    4 unsigned l_801 = 36901;
    5 ++l_801;
    -> 6 if (a) // optimize_me_not0
    7 b = 0;
    8 }

Process 10166 launched: '/home/sding/LLDB-testing/reduce/30986/report/a.out' (x86_64)
(lldb) p l_801
(unsigned int) $0 = 36901
(lldb) kill
Process 10166 exited with status = 9 (0x00000009)
(lldb) q

$ clang-trunk -g abc.c -O0
$ lldb-trunk -s cmds -b a.out
(lldb) target create "a.out"
Current executable set to '/home/sding/LLDB-testing/reduce/30986/report/a.out' (x86_64).
(lldb) command source -s 0 'cmds'
Executing commands in '/home/sding/LLDB-testing/reduce/30986/report/cmds'.
(lldb) b 6
Breakpoint 1: where = a.out`main + 43 at abc.c:6:7, address = 0x00000000004004ab
(lldb) r
Process 18492 stopped

  • thread #​1, name = 'a.out', stop reason = breakpoint 1.1
    frame #​0: 0x00000000004004ab a.out`main at abc.c:6:7
    3 --b;
    4 unsigned l_801 = 36901;
    5 ++l_801;
    -> 6 if (a) // optimize_me_not0
    7 b = 0;
    8 }

Process 18492 launched: '/home/sding/LLDB-testing/reduce/30986/report/a.out' (x86_64)
(lldb) p l_801
(unsigned int) $0 = 36902
(lldb) kill
Process 18492 exited with status = 9 (0x00000009)
(lldb) q

$ cat abc.c
char a, b;
int main() {
--b;
unsigned l_801 = 36901;
++l_801;
if (a) // optimize_me_not0
b = 0;
}

$ cat cmds
b 6
r
p l_801
kill
q

@jmorse
Copy link
Member

jmorse commented Nov 11, 2019

Going into LiveDebugVariables:

DBG_VALUE 36901, $noreg, !"l_801", !DIExpression(), 
DBG_VALUE 36901, $noreg, !"l_801", !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value),

Coming out of VirtRegRewriter:

DBG_VALUE 36901, $noreg, !"l_801", !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value),
DBG_VALUE 36901, $noreg, !"l_801", !DIExpression(),

It looks like LiveDebugVariables loses the original order of locations; it should be only preserving the last location given in each block of DBG_VALUEs.

(CC Orlando, who's wrestling with relevant LiveDebugVariables code in bug 41992)

@jmorse
Copy link
Member

jmorse commented Nov 12, 2019

I wrote:

(CC Orlando, who's wrestling with relevant LiveDebugVariables code in bug 41992)

Actually, this might be bug 41992. Because LiveDebugVariables incorrectly distinguishes variables by their whole expression, those DBG_VALUEs will be interpreted as two different variables, and LiveDebugVariables probably tries to preserve both.

Orlandos WIP patch should be up today, we can test with that.

@OCHyams
Copy link
Contributor

OCHyams commented Nov 12, 2019

Actually, this might be bug 41992.

This looks likely. With my upcoming patch, diffing the output of the following commands (pre-patch, patch):

$ clang -O3 -emit-llvm -S -g abc.c
$ llc -stop-after=livedebugvars abc.ll

gives:

bb.0 (%ir-block.0):
renamable $al = MOV8rm $rip, 1, $noreg, @​b, $noreg, debug-location !​20 :: (dereferenceable load 1 from @​b, !tbaa !​21)
renamable $al = ADD8ri killed renamable $al, -1, implicit-def dead $eflags, debug-location !​20
renamable $ecx = XOR32rr undef $ecx, undef $ecx, implicit-def dead $eflags
DBG_VALUE 36901, $noreg, !​18, !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value), debug-location !​24

[- DBG_VALUE 36901, $noreg, !​18, !DIExpression(), debug-location !​24-]

CMP8mi $rip, 1, $noreg, @​a, $noreg, 0, implicit-def $eflags, debug-location !​25 :: (dereferenceable load 1 from @​a, !tbaa !​21)
renamable $eax = MOVZX32rr8 killed renamable $al, debug-location !​27
renamable $eax = CMOV32rr killed renamable $eax, killed renamable $ecx, 5, implicit killed $eflags, debug-location !​27
MOV8mr $rip, 1, $noreg, @​b, $noreg, renamable $al, implicit killed $eax, debug-location !​24 :: (store 1 into @​b)
$eax = XOR32rr undef $eax, undef $eax, implicit-def dead $eflags, debug-location !​28
RETQ $eax, debug-location !​28

@OCHyams
Copy link
Contributor

OCHyams commented Nov 12, 2019

WIP patch here https://reviews.llvm.org/D70121

@OCHyams
Copy link
Contributor

OCHyams commented Feb 13, 2020

Fixed with D74053 (1e40799).

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:codegen
Projects
None yet
Development

No branches or pull requests

3 participants