<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:SimSun;
        mso-fareast-language:ZH-CN;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:SimSun;
        mso-fareast-language:ZH-CN;}
code
        {mso-style-priority:99;
        font-family:SimSun;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:SimSun;
        mso-fareast-language:ZH-CN;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        mso-fareast-language:ZH-CN;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The braces around the body of the 'for' statement indicate grouping, but don't have any other semantic significance.  If you look at the abstract syntax tree
 (AST) constructed for this by any compiler, it is highly unlikely to have an explicit representation of the braces, because the structure of the AST already describes the grouping.  On the other hand, a 'continue' statement will be explicitly represented in
 the AST because it is a statement in its own right.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">If I modify your for-loop body to this:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">  {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">    i++;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">#ifdef CONTINUE<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">    continue;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">#endif<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Courier New";color:#1F497D">  }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">and compile it both ways, then I see the same thing you do:  The generated IR is the same for both cases except for the source-location of the branch.  This
 makes sense to me as follows.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">A 'for' loop has four parts: initialization, condition, increment, and body.  Clang emits the condition and increment parts in their own basic-blocks, for convenience. 
 This means it implicitly needs to add a branch at the end of the "body" block to the "increment" block.  However, if the "body" block already ends with an explicit branch (of any kind), then it can omit the implicit branch.  The 'continue' statement will obviously
 be generated as an explicit branch to the "increment" block.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">The difference in debug-info is that the explicit branch is associated with the 'continue' statement, while the implicit branch is associated with the 'for'
 statement, and these statements have different source locations.  Even though the sequence of instructions is the same, the *reason* they were emitted is different, and the debug info reflects that difference.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">--paulr<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org]
<b>On Behalf Of </b>Frozen via llvm-dev<br>
<b>Sent:</b> Friday, June 02, 2017 8:44 AM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [llvm-dev] How the LLVM handle the debug location information of continue keyword and right brace(loop end location)?<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">Let me show you the following simple C code:<o:p></o:p></span></p>
<pre style="background:#EFF0F1;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit;max-height: 600px;word-wrap: normal;overflow:auto"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">int main()<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">{<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  int i;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in"><o:p> </o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  {<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">      i++;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  }<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">}<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">In this simple C code, if we use Clang to compile it and debug it: We will get something like this:<o:p></o:p></span></p>
<pre style="background:#EFF0F1;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit;max-height: 600px;word-wrap: normal;overflow:auto"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) b main<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">Breakpoint 1 at 0x100000f7b: file a.c, line 5.<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) r<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">Starting program: a.out <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">[New Thread 0x1403 of process 23435]<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">warning: unhandled dyld version (15)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in"><o:p> </o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">Thread 2 hit Breakpoint 1, main () at a.c:5<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">5     for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) n<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">7         i++;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">5     for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">7         i++;<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">That is to say, the right brace of location LLVM doesn't emit. However if we have the continue keyword:<o:p></o:p></span></p>
<pre style="background:#EFF0F1;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit;max-height: 600px;word-wrap: normal;overflow:auto"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">int main()<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">{<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  int i;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in"><o:p> </o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  {<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">    continue;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">    i++;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">  }<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">}<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">Then we compile and debug it:<o:p></o:p></span></p>
<pre style="background:#EFF0F1;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit;max-height: 600px;word-wrap: normal;overflow:auto"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">Thread 2 hit Breakpoint 1, main () at a.c:5<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">5     for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) n<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">7       continue;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">5     for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">7       continue;<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">5     for (i = 0; i < 256; i++)<o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">(gdb) <o:p></o:p></span></code></pre>
<pre style="background:#EFF0F1;vertical-align:baseline"><code><span style="font-family:Consolas;color:#242729;border:none windowtext 1.0pt;padding:0in">7       continue;<o:p></o:p></span></code></pre>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">We will stop the line of continue. But if we compare the LLVM IR between them:<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">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.<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">; :6: ; preds = %3 br label %7, !dbg !23<o:p></o:p></span></p>
<p style="mso-margin-top-alt:0in;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;vertical-align:baseline;font-variant-numeric: inherit;font-stretch: inherit;line-height:inherit">
<span style="font-size:11.5pt;font-family:"Arial","sans-serif";color:#242729">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.<o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<p> <o:p></o:p></p>
</div>
</div>
</body>
</html>