[LLVMbugs] [Bug 19864] New: debug info fail -- range based for loops and other stuff

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon May 26 23:41:45 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=19864

            Bug ID: 19864
           Summary: debug info fail -- range based for loops and other
                    stuff
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chandlerc at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

So, I came here to file a bug about debug info for range-based for loops. I
wrote the following test case:

----
#include <vector>
#include <iostream>

int main() {
  std::vector<int> v = {13, 21, 8, 3, 34, 1, 5, 2};
  std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3]
            << ", " << v[4] << ", " << v[5] << ", " << v[6] << ", " << v[7]
            << "}\n";

  int size = v.size();
  if (v.size() > 3) {
    int a = 0, b = 0;
    for (int x : v)
      if (x >= size)
        ++b;
      else if (x >= 0)
        ++a;
    std::cout << "a = " << a << "\n";
    std::cout << "b = " << b << "\n";
  }
}
----

Then I compiled and debugged it:

% clang++ -std=c++11 -g -o x x.cc
% gdb --args ./x
GNU gdb (GDB) 7.6.50.20130820-cvs
<snip>
Reading symbols from .../x...done.
(gdb) break main
Breakpoint 1 at 0x400b92: file x.cc, line 5.
(gdb) r
Starting program: .../x
<snip>

Breakpoint 1, main () at x.cc:5
5         std::vector<int> v = {13, 21, 8, 3, 34, 1, 5, 2};
(gdb) n
6         std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", "
<< v[3]
(gdb) 
7                   << ", " << v[4] << ", " << v[5] << ", " << v[6] << ", " <<
v[7]
(gdb) 
6         std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", "
<< v[3]
(gdb) 
7                   << ", " << v[4] << ", " << v[5] << ", " << v[6] << ", " <<
v[7]
(gdb) 
6         std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", "
<< v[3]
(gdb) 
7                   << ", " << v[4] << ", " << v[5] << ", " << v[6] << ", " <<
v[7]
(gdb) 
6         std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", "
<< v[3]
(gdb) 
7                   << ", " << v[4] << ", " << v[5] << ", " << v[6] << ", " <<
v[7]
(gdb) 
6         std::cout << "v = {" << v[0] << ", " << v[1] << ", " << v[2] << ", "
<< v[3]


WAT. I have no idea what happened here. But again, this is not why I wanted to
file the bug, its just something we should fix. Continuing with GDB...


(gdb) 
v = {13, 21, 8, 3, 34, 1, 5, 2}
10        int size = v.size();
(gdb) 
11        if (v.size() > 3) {
(gdb) 
12          int a = 0, b = 0;
(gdb) 
13          for (int x : v)
(gdb) 
14            if (x >= size)
(gdb) 
15              ++b;
(gdb) 
17              ++a;

BUG: We never execute both ++b and ++a. This is a bogus line to jump to, I
think it's actually trying to jump to the "end" of the body of the range based
for loop, and has this as the source location or something. The *behavior* of
this program is entirely correct, but the debugger is lying to me.

(gdb) 
13          for (int x : v)
(gdb) 
14            if (x >= size)
(gdb) 
15              ++b;
(gdb) 
17              ++a;

And it happens on every loop where we execute "++b".

(gdb) 
13          for (int x : v)
(gdb) 
14            if (x >= size)
(gdb) 
15              ++b;
(gdb) 
17              ++a;
(gdb) 
13          for (int x : v)
(gdb) 
14            if (x >= size)
(gdb) 
16            else if (x >= 0)
(gdb) 
17              ++a;
(gdb) 
13          for (int x : v)

But we only see one stop at that line when we execute "++a".

Let me know what else I can provide to help fix!

-- 
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/20140527/25a18e93/attachment.html>


More information about the llvm-bugs mailing list