<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 - Out-of-order Stepping Behavior Introduced for Constant Infinite Loops at O0"
   href="https://bugs.llvm.org/show_bug.cgi?id=41953">41953</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Out-of-order Stepping Behavior Introduced for Constant Infinite Loops at O0
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>matthew.voss@sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>This behavior is seen at O0 with debug info enabled.  It is observed with
constant infinite 'while' and 'for' loops. For example:

$ nl test.cpp
1  int main(void) {
2    int a = 0;
3    while (true)
4      ++a;
5    return a;
6  }
$

When first stepping into the program the debugger will step to line 4, then
line 3. Under some circumstances this would be acceptable for an infinite loop,
but imagine that the user sets a breakpoint at line 3. If they run the program
and ask for the value of 'a', the debugger will report a value of 1, making it
look as if the debugger has skipped an iteration.

Looking at the IR, the line entry for the top of the loop is now attached to an
unconditional branch at the bottom of the loop body.

$ clang --version | grep version
clang version 9.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a> f672b6170c...
$ clang -g -S -emit-llvm test.cpp
$ cat test.ll
...
define i32 @main() #0 !dbg !8 {
entry:
...
while.body:
  %0 = load i32, i32* %a, align 4, !dbg !16
  %inc = add nsw i32 %0, 1, !dbg !16
  store i32 %inc, i32* %a, align 4, !dbg !16
  br label %while.body, !dbg !17, !llvm.loop !19
}
...
!16 = !DILocation(line: 4, scope: !8)
!17 = !DILocation(line: 3, scope: !18)
...

The leads to the out-of-order stepping behavior seen in the debugger.</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>