[llvm-bugs] [Bug 41953] New: Out-of-order Stepping Behavior Introduced for Constant Infinite Loops at O0

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 20 17:47:37 PDT 2019


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

            Bug ID: 41953
           Summary: Out-of-order Stepping Behavior Introduced for Constant
                    Infinite Loops at O0
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: matthew.voss at sony.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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 (https://github.com/llvm/llvm-project.git 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.

-- 
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/20190521/de9d7028/attachment-0001.html>


More information about the llvm-bugs mailing list