[llvm-bugs] [Bug 38773] New: [DebugInfo][Dexter] Divide-before-return displays wrong value in debugger

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 30 04:53:15 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38773

            Bug ID: 38773
           Summary: [DebugInfo][Dexter] Divide-before-return displays
                    wrong value in debugger
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: wrong-debug
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: jeremy.morse.llvm at gmail.com
                CC: aprantl at apple.com, chackz0x12 at gmail.com,
                    dblaikie at gmail.com, greg.bedwell at sony.com,
                    international.phantom at gmail.com,
                    jdevlieghere at apple.com, llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com
            Blocks: 38768

Under a debugger the test below reports the wrong return value, on the return
statement, which is misleading. The program should take the "case 3" path
through the switch, divide four by four to reach one, and return that.

Compiling with llvm/clang @ r340912 and options "-O2 -g" for x86_64, both gdb
and lldb step through the program just fine, but on the return statement "print
read1" reports the value four, while "print $rax" reports one (when parked on
the ret insn).

This test is supposed to stimulate SimplifyCFGs SimplifySelectOnSwitch, which
turns the switch into a conditional branch. Dwarf data further down shows
DebugInfo is wrong, and I get the feeling this must be lower than SimplifyCFG
because the transform is simple, and it doesn't go wrong if one takes the other
path through the switch.

-------->8--------
int
main()
{
  volatile int foo = 4;
  int read1 = foo;
  int read2 = foo;

  switch ((read1 == 4) ? 3 : 1) {
  case 1:
    read1 *= read2;
    break;
  case 3:
    read1 /= read2;
    break;
  }

  return read1;
}
--------8<--------

The trimmed output of `llvm-dwarfdump --name=read1`:
-------->8--------
0x00000051: DW_TAG_variable
              DW_AT_location    (0x00000000
                 0x000000000000000c - 0x000000000000001a: DW_OP_reg0 RAX
                 0x000000000000001e - 0x000000000000001f: DW_OP_reg2 RCX
                 0x000000000000001f - 0x0000000000000022: DW_OP_reg0 RAX
                 0x0000000000000022 - 0x0000000000000025: DW_OP_reg2 RCX)
              DW_AT_name        ("read1")
--------8<--------

And the "case 3" branch of the switch:

-------->8--------
   0x00000000004004b5 <+21>:    mov    $0x4,%eax
   0x00000000004004ba <+26>:    xor    %edx,%edx
   0x00000000004004bc <+28>:    idiv   %ecx
=> 0x00000000004004be <+30>:    retq
--------8<--------

(Start addr for the function is 0x4004a0). The output of idiv is eax, but the
location data specifically moves the location of read1 to ecx for the return
instruction, which is wrong (AFAICT).


Referenced Bugs:

https://bugs.llvm.org/show_bug.cgi?id=38768
[Bug 38768] [meta][DebugInfo] Umbrella bug for poor debug experiences
-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180830/7b2f244f/attachment.html>


More information about the llvm-bugs mailing list