[llvm-bugs] [Bug 51648] New: Inconsistent variable value and assembly mapping at Og

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 27 09:25:19 PDT 2021


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

            Bug ID: 51648
           Summary: Inconsistent variable value and assembly mapping at Og
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: DebugInfo
          Assignee: unassignedbugs at nondot.org
          Reporter: artuso 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

Comment:
The code exhibits an odd stepping behaviour with inconsistent values of
variables.
The code steps on line 11, 13, line 0 and it goes back to line 12.

After stepping on line 13, the debuggers steps on "movl $0x1, 0x200aec(%rip)"
which set g_3 to 1. Then the debugger steps back at line 12. However, if g_3 is
equal to one, we should have exited the for cycle at line 6 and so we could not
be at line 12 with g_3 equal to 1.
If we print g_3 at line 12 we can see that is equal to 1, this is also
inconsistent with the value of l_5[4] that is, correctly, equal to 0. But has
been assigned to g_3 at line 11.
Finally, when stepping at line 12 the assembly instruction shown is movb $0x1,
0x200ae3(%rip), which is inconsistent with the source code (the value that
should be moved should be 0 and not 1, this is probably related to the fact
that g_3 is equal to 1).

Steps to reproduce bug:

root at b82d9377034e:/home/stepping/output# clang -v
clang version 14.0.0 (https://github.com/llvm/llvm-project.git
957334382cd12ec07b46c0ddfdcc220731f6d80f)
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
root at b82d9377034e:/home/stepping/output# lldb -v
lldb version 14.0.0 (https://github.com/llvm/llvm-project.git revision
957334382cd12ec07b46c0ddfdcc220731f6d80f)
  clang revision 957334382cd12ec07b46c0ddfdcc220731f6d80f
  llvm revision 957334382cd12ec07b46c0ddfdcc220731f6d80f
root at b82d9377034e:/home/stepping/output# cat a.c
int a, g_3, b, d;
static int g_8 = 9;
char c;
char func_1() {
  g_3 = 0;
  for (; g_3 <= 0; g_3++) {
    int l_5[9];
    d = 0;
    for (; d < 9; d++)
      l_5[d] = 0;
    l_5[4] = g_3;
    g_8 = l_5[4];
    if (c) {
      b = l_5;
      return;
    }
  }
}
int main() {
  func_1();
  a = g_8;
}
root at b82d9377034e:/home/stepping/output# cat -n a.c
     1  int a, g_3, b, d;
     2  static int g_8 = 9;
     3  char c;
     4  char func_1() {
     5    g_3 = 0;
     6    for (; g_3 <= 0; g_3++) {
     7      int l_5[9];
     8      d = 0;
     9      for (; d < 9; d++)
    10        l_5[d] = 0;
    11      l_5[4] = g_3;
    12      g_8 = l_5[4];
    13      if (c) {
    14        b = l_5;
    15        return;
    16      }
    17    }
    18  }
    19  int main() {
    20    func_1();
    21    a = g_8;
    22  }
root at b82d9377034e:/home/stepping/output# clang -Og -g -Wno-everything -o opt
a.c
root at b82d9377034e:/home/stepping/output# lldb opt
(lldb) target create "opt"
Current executable set to '/home/stepping/output/opt' (x86_64).
(lldb) b main
Breakpoint 1: where = opt`main + 7 [inlined] func_1 at a.c:11:12, address =
0x00000000004004f7
(lldb) r
Process 128 launched: '/home/stepping/output/opt' (x86_64)
Process 128 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x00000000004004f7 opt`main at a.c:11:12
   8        d = 0;
   9        for (; d < 9; d++)
   10         l_5[d] = 0;
-> 11       l_5[4] = g_3;
   12       g_8 = l_5[4];
   13       if (c) {
   14         b = l_5;
(lldb) s
Process 128 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x000000000040050c opt`main at a.c:13:9
   10         l_5[d] = 0;
   11       l_5[4] = g_3;
   12       g_8 = l_5[4];
-> 13       if (c) {
   14         b = l_5;
   15         return;
   16       }
(lldb) si
Process 128 stopped
* thread #1, name = 'opt', stop reason = instruction step into
    frame #0: 0x0000000000400536 opt`main [inlined] func_1 at a.c:0
   1    int a, g_3, b, d;
   2    static int g_8 = 9;
   3    char c;
   4    char func_1() {
   5      g_3 = 0;
   6      for (; g_3 <= 0; g_3++) {
   7        int l_5[9];
(lldb) di -l
opt`main:
->  0x400536 <+70>: movl   $0x1, 0x200aec(%rip)      ; completed.7698
    0x400540 <+80>: movl   $0x9, 0x200ae6(%rip)      ; g_3
(lldb) p g_3
(int) $0 = 0
(lldb) si
Process 128 stopped
* thread #1, name = 'opt', stop reason = instruction step into
    frame #0: 0x0000000000400540 opt`main at a.c:0
   1    int a, g_3, b, d;
   2    static int g_8 = 9;
   3    char c;
   4    char func_1() {
   5      g_3 = 0;
   6      for (; g_3 <= 0; g_3++) {
   7        int l_5[9];
(lldb) p g_3
(int) $1 = 1
(lldb) di -l
opt`main:
    0x400536 <+70>: movl   $0x1, 0x200aec(%rip)      ; completed.7698
->  0x400540 <+80>: movl   $0x9, 0x200ae6(%rip)      ; g_3
(lldb) p d
(int) $2 = 0
(lldb) si
Process 128 stopped
* thread #1, name = 'opt', stop reason = instruction step into
    frame #0: 0x000000000040054a opt`main at a.c:12:9
   9        for (; d < 9; d++)
   10         l_5[d] = 0;
   11       l_5[4] = g_3;
-> 12       g_8 = l_5[4];
   13       if (c) {
   14         b = l_5;
   15         return;
(lldb) di -l
opt`main:
->  0x40054a <+90>: movb   $0x1, 0x200ae3(%rip)      ; d + 3
(lldb) p d
(int) $3 = 9
(lldb) p l_5
(int [9]) $5 = ([0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 0,
[7] = 0, [8] = 0)
(lldb) p g_8
(int) $6 = 9
(lldb) si
Process 128 stopped
* thread #1, name = 'opt', stop reason = instruction step into
    frame #0: 0x0000000000400551 opt`main at a.c:21:7
   18   }
   19   int main() {
   20     func_1();
-> 21     a = g_8;
   22   }
(lldb) p g_8
(int) $7 = 0

-- 
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/20210827/8b9bde25/attachment.html>


More information about the llvm-bugs mailing list