[llvm-bugs] [Bug 47274] New: Odd stepping behaviour at Og

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 21 11:35:32 PDT 2020


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

            Bug ID: 47274
           Summary: Odd stepping behaviour at Og
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: massarelli at diag.uniroma1.it
                CC: jdevlieghere at apple.com, keith.walker at arm.com,
                    llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com

Odd stepping behavior. 'func_2' calls function 'b' at line 17. After return
from function 'b' line 14 is hit.

$ cat -n a.c
     1  int a,  c ;
     2  int d[1] ;
     3  void __assert_fail ()
     4  ;
     5  short
     6  b(e )
     7  {
     8    return
     9      e >> a
    10  ;
    11  }
    12  void  func_2()
    13  {
    14      int *l_368 = d;
    15      int f = 1;
    16      int g = c = 0;
    17      if (b(3))
    18          (*l_368) = 6;
    19      else
    20          for (; g < 10; g++)
    21          l_368 = &f;
    22      l_368 == &f || d[0] ? (void) 0 : __assert_fail ();
    23  }
    24  int main ()
    25      {
    26             func_2();
    27      }

$ cat a.c
int a,  c ;
int d[1] ;
void __assert_fail ()
;
short
b(e )
{
  return
    e >> a
;
}
void  func_2()
{
    int *l_368 = d;
    int f = 1;
    int g = c = 0;
    if (b(3))
        (*l_368) = 6;
    else
        for (; g < 10; g++)
        l_368 = &f;
    l_368 == &f || d[0] ? (void) 0 : __assert_fail ();
}
int main ()
    {
           func_2();
    }

$ clang -v
clang version 12.0.0 (https://github.com/llvm/llvm-project.git
bc8be3054067ac822fc6d9f4f8e64c841f530f16)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ clang -Og -g -o opt a.c

$ lldb opt

(lldb) target create "opt"
Current executable set to 'opt' (x86_64).
(lldb) b func_2
Breakpoint 1: where = opt`func_2 + 1 at a.c:15:9, address = 0x00000000004004f1
(lldb) r
Process 225 launched: 'opt' (x86_64)
Process 225 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004f1 opt`func_2 at a.c:15:9
   12   void  func_2()
   13   {
   14       int *l_368 = d;
-> 15       int f = 1;
   16       int g = c = 0;
   17       if (b(3))
   18           (*l_368) = 6;
(lldb) s
Process 225 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x00000000004004f9 opt`func_2 at a.c:16:15
   13   {
   14       int *l_368 = d;
   15       int f = 1;
-> 16       int g = c = 0;
   17       if (b(3))
   18           (*l_368) = 6;
   19       else
(lldb) s
Process 225 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400503 opt`func_2 at a.c:17:9
   14       int *l_368 = d;
   15       int f = 1;
   16       int g = c = 0;
-> 17       if (b(3))
   18           (*l_368) = 6;
   19       else
   20           for (; g < 10; g++)
(lldb) s
Process 225 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x00000000004004e2 opt`b(e=3) at a.c:9:10
   6    b(e )
   7    {
   8      return
-> 9        e >> a
   10   ;
   11   }
   12   void  func_2()
(lldb) s
Process 225 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x00000000004004ea opt`b(e=<unavailable>) at a.c:8:3
   5    short
   6    b(e )
   7    {
-> 8      return
   9        e >> a
   10   ;
   11   }
(lldb) s
Process 225 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400512 opt`func_2 at a.c:14:10
   11   }
   12   void  func_2()
   13   {
-> 14       int *l_368 = d;
   15       int f = 1;
   16       int g = c = 0;
   17       if (b(3))
(lldb) bt
* thread #1, name = 'opt', stop reason = step in
  * frame #0: 0x0000000000400512 opt`func_2 at a.c:14:10
    frame #1: 0x0000000000400546 opt`main at a.c:26:12
    frame #2: 0x00007ffff7a05b97 libc.so.6`__libc_start_main + 231
    frame #3: 0x000000000040041a opt`_start + 42
(lldb) di 
opt`func_2:
    0x4004f0 <+0>:  pushq  %rax
    0x4004f1 <+1>:  movl   $0x1, 0x4(%rsp)
    0x4004f9 <+9>:  movl   $0x0, 0x200b39(%rip)      ; d
    0x400503 <+19>: movl   $0x3, %edi
    0x400508 <+24>: callq  0x4004e0                  ; b at a.c:7
    0x40050d <+29>: leaq   0x4(%rsp), %rcx
->  0x400512 <+34>: movq   %rcx, %rdx
    0x400515 <+37>: testw  %ax, %ax
    0x400518 <+40>: je     0x400529                  ; <+57> at a.c:22:11
    0x40051a <+42>: movl   $0x6, 0x200b14(%rip)      ; a
    0x400524 <+52>: movl   $0x601038, %edx           ; imm = 0x601038 
    0x400529 <+57>: cmpq   %rcx, %rdx
    0x40052c <+60>: je     0x40053e                  ; <+78> at a.c:23:1
    0x40052e <+62>: cmpl   $0x0, 0x200b03(%rip)      ; a + 3
    0x400535 <+69>: jne    0x40053e                  ; <+78> at a.c:23:1
    0x400537 <+71>: xorl   %eax, %eax
    0x400539 <+73>: callq  0x4003e0                  ; symbol stub for:
__assert_fail
    0x40053e <+78>: popq   %rax
    0x40053f <+79>: retq   

Looking at the assembly code it seems that it is actually executing line 21.

-- 
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/20200821/6bfcddc4/attachment.html>


More information about the llvm-bugs mailing list