<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 - Variable's value not available from second loop iteration at Og"
   href="https://bugs.llvm.org/show_bug.cgi?id=52239">52239</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Variable's value not available from second loop iteration 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>cristianassaiante@outlook.com
          </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>Variable l_143 value is not available at line 9 and 10 from the second loop
iteration, in fact it is only available at line 13 in the loop body.
>From bisect, this behavior may be caused by PostOrderFunctionAttrsPass on SCC
(f)

$ cat a.c
char a;
long b;
volatile int d;
char e(c) {
    return a;
}
void f() {
    int l_143 = 0;
    for (;
        b != 3;
        ++b) {
        l_143 = 0;
        l_143 = e(d);
    }
}
int main () {
    f();
}

$ clang -v
clang version 13.0.0
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 13.0.0

$ clang -g -Og -o opt a.c
(lldb) target create "opt"
Current executable set to '/home/stepping/56/reduce/opt' (x86_64).
(lldb) b 10
Breakpoint 1: 2 locations.
(lldb) run
Process 247 launched: '/home/stepping/56/reduce/opt' (x86_64)
Process 247 stopped
* thread #1, name = 'opt', stop reason = breakpoint 1.2
    frame #0: 0x00000000004004d0 opt`main [inlined] f at a.c:10:9
   7    void f() {
   8        int l_143 = 0;
   9        for (;
-> 10           b != 3;
   11           ++b) {
   12           l_143 = 0;
   13           l_143 = e(d);
(lldb) frame var
(int) l_143 = 0
(lldb) n
Process 247 stopped
* thread #1, name = 'opt', stop reason = step over
    frame #0: 0x00000000004004db opt`main [inlined] f at a.c:9:5
   6    }
   7    void f() {
   8        int l_143 = 0;
-> 9        for (;
   10           b != 3;
   11           ++b) {
   12           l_143 = 0;
(lldb) frame var
(int) l_143 = 0
(lldb) n
Process 247 stopped
* thread #1, name = 'opt', stop reason = step over
    frame #0: 0x00000000004004f0 opt`main [inlined] f at a.c:13:19
   10           b != 3;
   11           ++b) {
   12           l_143 = 0;
-> 13           l_143 = e(d);
   14       }
   15   }
   16   int main () {
(lldb) n
Process 247 stopped
* thread #1, name = 'opt', stop reason = step over
    frame #0: 0x00000000004004f6 opt`main [inlined] f at a.c:10:11
   7    void f() {
   8        int l_143 = 0;
   9        for (;
-> 10           b != 3;
   11           ++b) {
   12           l_143 = 0;
   13           l_143 = e(d);
(lldb) frame var
(int) l_143 = <variable not available>

(lldb) n
Process 247 stopped
* thread #1, name = 'opt', stop reason = step over
    frame #0: 0x00000000004004f9 opt`main [inlined] f at a.c:9:5
   6    }
   7    void f() {
   8        int l_143 = 0;
-> 9        for (;
   10           b != 3;
   11           ++b) {
   12           l_143 = 0;
(lldb) frame var
(int) l_143 = <variable not available>

(lldb) n
Process 247 stopped
* thread #1, name = 'opt', stop reason = step over
    frame #0: 0x00000000004004f0 opt`main [inlined] f at a.c:13:19
   10           b != 3;
   11           ++b) {
   12           l_143 = 0;
-> 13           l_143 = e(d);
   14       }
   15   }
   16   int main () {
(lldb) frame var
(int) l_143 = 0</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>