[llvm-dev] How the LLVM handle the debug location information of continue keyword and right brace(loop end location)?

Frozen via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 2 08:44:01 PDT 2017


Let me show you the following simple C code:

int main()
{
  int i;

  for (i = 0; i < 256; i++)
  {
      i++;
  }
}


In this simple C code, if we use Clang to compile it and debug it: We will get something like this:

(gdb) b main
Breakpoint 1 at 0x100000f7b: file a.c, line 5.
(gdb) r
Starting program: a.out 
[New Thread 0x1403 of process 23435]
warning: unhandled dyld version (15)

Thread 2 hit Breakpoint 1, main () at a.c:5
5     for (i = 0; i < 256; i++)
(gdb) n
7         i++;
(gdb) 
5     for (i = 0; i < 256; i++)
(gdb) 
7         i++;


That is to say, the right brace of location LLVM doesn't emit. However if we have the continue keyword:

int main()
{
  int i;

  for (i = 0; i < 256; i++)
  {
    continue;
    i++;
  }
}


Then we compile and debug it:

Thread 2 hit Breakpoint 1, main () at a.c:5
5     for (i = 0; i < 256; i++)
(gdb) n
7       continue;
(gdb) 
5     for (i = 0; i < 256; i++)
(gdb) 
7       continue;
(gdb) 
5     for (i = 0; i < 256; i++)
(gdb) 
7       continue;


We will stop the line of continue. But if we compare the LLVM IR between them:

The right brace and continue keyword both are the following the br instruction and !dbg !23. Except that the line number of !dbg !23 not the same.

; :6: ; preds = %3 br label %7, !dbg !23

The question is how LLVM know whether to generate the debug location(generate for the continue keyword line, but not for the loop's right brace)? Because they are the same br instruction and others are the same.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170602/758186d1/attachment.html>


More information about the llvm-dev mailing list