<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 - Missing Variables information at Og"
   href="https://bugs.llvm.org/show_bug.cgi?id=47093">47093</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missing Variables information at Og
          </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>jdevlieghere@apple.com, keith.walker@arm.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>At line 9 lldb says that variables l_1876 and l_2441 are optimized out, but
they are actually used.

$ cat -n a.c
     1  short a;
     2  int b, d = 4;
     3  int *c = &b;
     4  void func_3() {
     5    int **l_1876 = &c;
     6    int e = 1;
     7    if (d) {
     8      int *l_2441 = a;
     9      (**l_1876) = l_2441;
    10    }
    11    *l_1876 = &e;
    12  }
    13  int main() { func_3(); }

$ cat a.c
short a;
int b, d = 4;
int *c = &b;
void func_3() {
  int **l_1876 = &c;
  int e = 1;
  if (d) {
    int *l_2441 = a;
    (**l_1876) = l_2441;
  }
  *l_1876 = &e;
}
int main() { func_3(); }


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

$ lldb -v
lldb version 12.0.0
  clang revision bc8be3054067ac822fc6d9f4f8e64c841f530f16
  llvm revision bc8be3054067ac822fc6d9f4f8e64c841f530f16


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

$ lldb opt
(lldb) target create "opt"
Current executable set to 'opt' (x86_64).
(lldb) b func_3
Breakpoint 1: where = opt`func_3 at a.c:6:7, address = 0x0000000000400480
(lldb) r
Process 66 launched: '/home/stepping/output/opt' (x86_64)
Process 66 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.1
    frame #0: 0x0000000000400480 opt`func_3 at a.c:6:7
   3    int *c = &b;
   4    void func_3() {
   5      int **l_1876 = &c;
-> 6      int e = 1;
   7      if (d) {
   8        int *l_2441 = a;
   9        (**l_1876) = l_2441;
(lldb) s
Process 66 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400488 opt`func_3 at a.c:7:7
   4    void func_3() {
   5      int **l_1876 = &c;
   6      int e = 1;
-> 7      if (d) {
   8        int *l_2441 = a;
   9        (**l_1876) = l_2441;
   10     }
(lldb) s
Process 66 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400491 opt`func_3 at a.c:8:19
   5      int **l_1876 = &c;
   6      int e = 1;
   7      if (d) {
-> 8        int *l_2441 = a;
   9        (**l_1876) = l_2441;
   10     }
   11     *l_1876 = &e;
(lldb) s
Process 66 stopped
* thread #1, name = 'opt', stop reason = step in
    frame #0: 0x0000000000400498 opt`func_3 at a.c:9:7
   6      int e = 1;
   7      if (d) {
   8        int *l_2441 = a;
-> 9        (**l_1876) = l_2441;
   10     }
   11     *l_1876 = &e;
   12   }
(lldb) p l_2441
error: Couldn't materialize: couldn't get the value of variable l_2441: no
location, value may have been optimized out
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) p l_1876
error: Couldn't materialize: couldn't get the value of variable l_1876: no
location, value may have been optimized out
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) di
opt`func_3:
    0x400480 <+0>:  movl   $0x1, -0x4(%rsp)
    0x400488 <+8>:  cmpl   $0x0, 0x200b99(%rip)      ; __dso_handle + 7
    0x40048f <+15>: je     0x4004a1                  ; <+33> at a.c
    0x400491 <+17>: movswl 0x200ba8(%rip), %eax      ; a
->  0x400498 <+24>: movq   0x200b91(%rip), %rcx      ; c
    0x40049f <+31>: movl   %eax, (%rcx)
    0x4004a1 <+33>: leaq   -0x4(%rsp), %rax
    0x4004a6 <+38>: movq   %rax, 0x200b83(%rip)      ; c
    0x4004ad <+45>: retq   
(lldb)</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>