<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><br><div><span style="color: rgb(0, 0, 0);">Hi </span><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">paulr:</span></font><br><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">    Thanks for your kindly response. Maybe I don't describe my question cleanly, let me show more information. From my side, I notice that whether we are in the continue keyword mode or we are in the right brace mode, the target of br instruction is the same, i.e. for loop</span></font><br><br><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">     Continue Keyword Mode:</span></font><br><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">; <label>:6:                                      ; preds = %3</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  <b>br label %7, !dbg !23</b></span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);"><br></span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">; <label>:7:                                      ; preds = %6</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  %8 = load i32, i32* %2, align 4, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  %9 = add nsw i32 %8, 1, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  store i32 %9, i32* %2, align 4, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  br label %3, !dbg !27, !llvm.loop !28<br><br>   Right Brace Mode:<br>   ; <label>:6:                                      ; preds = %3</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);"><b>  br label %7, !dbg !23</b></span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);"><br></span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">; <label>:7:                                      ; preds = %6</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  %8 = load i32, i32* %2, align 4, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  %9 = add nsw i32 %8, 1, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  store i32 %9, i32* %2, align 4, !dbg !25</span></font></div><div><font color="#1f497d" face="Calibri, sans-serif"><span style="font-size: 14.6667px; color: rgb(0, 0, 0);">  br label %3, !dbg !27, !llvm.loop !28</span></font></div><div><br></div><div>There are only different line number of !dbg!23. But my concern and question is:  <b>Why continue keyword can be emitted but right brace won't be emitted, and debbuger can stop at continue keyword statement but won't stop at right brace statement?</b> I know left / right brace is just to group and right brace statement should not be emitted debug location information. <b>But the br instruction is the same and only has different line number information in the debug metadata, how the llvm distinguish this is meaningful statement and not right brace?</b></div></div><br><div style="position:relative;zoom:1"></div><div id="divNeteaseMailCard"></div><br>At 2017-06-03 02:50:13, "Robinson, Paul" <paul.robinson@sony.com> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">



<style></style>


<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:<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>]
<b>On Behalf Of </b>Frozen via llvm-dev<br>
<b>Sent:</b> Friday, June 02, 2017 8:44 AM<br>
<b>To:</b> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><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>


</blockquote></div><br><br><span title="neteasefooter"><p> </p></span>