<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Wrong line information at O3"
   href="https://bugs.llvm.org/show_bug.cgi?id=46099">46099</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong line information at O3
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>DebugInfo
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>massarelli@diag.uniroma1.it
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>ditaliano@apple.com, jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Function b is wrongly hit after exit the for loop.
More precisely the third time the debugger shows to execute b is wrong.

$ cat a.c
static int a[1];
int(b)(c, d) { return (c & (c ^ 7) - d) < 0 ? 0 : c - d; }
short(e)(short c) { return c; }
static int *f() {
  short g = 6;
  for (; g > 0; g = b(g, 2))
    e(g);
  *a = g;
  return a;
}
int main() {
  int i, j, k, print_hash_value;
  f();
  printf("%X\n");
}

$ clang -v
clang version 11.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a>
da52aa2c3340d91025c0188175012c476967dc74)
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

$ lldb -v
lldb version 11.0.0
clang revision da52aa2c3340d91025c0188175012c476967dc74
llvm revision da52aa2c3340d91025c0188175012c476967dc74

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

 lldb opt 
(lldb) target create "opt"
Current executable set to 'opt' (x86_64).
(lldb) b main
Breakpoint 1: where = opt`main + 16 [inlined] f + 5 at test.c:13, address =
0x0000000000400510
(lldb) r
Process 118 launched: 'opt' (x86_64)
Process 118 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x0000000000400510 opt`main [inlined] f at test.c:6:10
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
-> 6      for (; g > 0; g = b(g, 2))
   7        e(g);
   8      *a = g;
   9      return a;
(lldb) p b
(int (*)(int, int)) $0 = 0x00000000004004d0 (opt`b at test.c:2:31)
(lldb) p g
(short) $1 = 4
(lldb) s
Process 118 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x000000000040051a opt`main [inlined] b(c=4, d=2) at test.c:2:31
   1    static int a[1];
-> 2    int(b)(c, d) { return (c & (c ^ 7) - d) < 0 ? 0 : c - d; }
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
   6      for (; g > 0; g = b(g, 2))
   7        e(g);
(lldb) expr (c & (c ^ 7) - d) < 0 ? 0 : c - d;
(int) $2 = 2
(lldb) s
Process 118 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x0000000000400510 opt`main [inlined] f at test.c:6:10
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
-> 6      for (; g > 0; g = b(g, 2))
   7        e(g);
   8      *a = g;
   9      return a;
(lldb) p g
(short) $3 = 2
(lldb) s
Process 118 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x000000000040051a opt`main [inlined] b(c=2, d=2) at test.c:2:31
   1    static int a[1];
-> 2    int(b)(c, d) { return (c & (c ^ 7) - d) < 0 ? 0 : c - d; }
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
   6      for (; g > 0; g = b(g, 2))
   7        e(g);
(lldb) expr (c & (c ^ 7) - d) < 0 ? 0 : c - d;
(int) $4 = 0
(lldb) frame var
(int) c = 2
(int) d = 2
(lldb) s
Process 118 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x0000000000400510 opt`main [inlined] f at test.c:6:10
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
-> 6      for (; g > 0; g = b(g, 2))
   7        e(g);
   8      *a = g;
   9      return a;
(lldb) p g
(short) $5 = 0
(lldb) s
Process 118 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x000000000040052f opt`main at test.c:2:23
   1    static int a[1];
-> 2    int(b)(c, d) { return (c & (c ^ 7) - d) < 0 ? 0 : c - d; }
   3    short(e)(short c) { return c; }
   4    static int *f() {
   5      short g = 6;
   6      for (; g > 0; g = b(g, 2))
   7        e(g);
(lldb) di
opt`main:
    0x400500 <+0>:  movw   $0x6, %ax
    0x400504 <+4>:  movl   $0x6, %ecx
    0x400509 <+9>:  jmp    0x40051a                  ; <+26> [inlined] b at
test.c:6
    0x40050b <+11>: nopl   (%rax,%rax)
    0x400510 <+16>: movswl %dx, %ecx
    0x400513 <+19>: movl   %edx, %eax
    0x400515 <+21>: testw  %cx, %cx
    0x400518 <+24>: jle    0x40052f                  ; <+47> at test.c:2:23
    0x40051a <+26>: movl   %ecx, %esi
    0x40051c <+28>: xorl   $0x7, %esi
    0x40051f <+31>: addl   $-0x2, %esi
    0x400522 <+34>: xorl   %edx, %edx
    0x400524 <+36>: testl  %ecx, %esi
    0x400526 <+38>: js     0x400510                  ; <+16> [inlined] f + 5 at
test.c:13
    0x400528 <+40>: addl   $-0x2, %eax
    0x40052b <+43>: movl   %eax, %edx
    0x40052d <+45>: jmp    0x400510                  ; <+16> [inlined] f + 5 at
test.c:13
->  0x40052f <+47>: pushq  %rax
    0x400530 <+48>: movl   $0x4005c4, %edi           ; imm = 0x4005C4 
    0x400535 <+53>: xorl   %eax, %eax
    0x400537 <+55>: callq  0x4003d0                  ; symbol stub for: printf
    0x40053c <+60>: xorl   %eax, %eax
    0x40053e <+62>: popq   %rcx
    0x40053f <+63>: retq</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>