[llvm-dev] How the LLVM handle the debug location information of continue keyword and right brace(loop end location)?
Robinson, Paul via llvm-dev
llvm-dev at lists.llvm.org
Mon Jun 5 10:31:42 PDT 2017
If we had a very naïve way of generating IR, in the 'continue' case you would actually see TWO branch instructions: one to implement the 'continue' statement, and one as part of the control flow of the 'for' loop. The branch for the 'continue' statement would have the source location of the 'continue' and the branch for the control-flow of the 'for' loop would have the source location of the right brace.
Clang is smart enough that in the 'continue' example, it knows not to emit the second branch (it would be unreachable).
--paulr
From: Frozen [mailto:bluechristlove at 163.com]
Sent: Saturday, June 03, 2017 8:13 AM
To: Marcin Słowik
Cc: llvm-dev at lists.llvm.org; Robinson, Paul
Subject: Re:Re: Re: [llvm-dev] How the LLVM handle the debug location information of continue keyword and right brace(loop end location)?
If without any brace, the br should correspond to doStuff() in your case. However, maybe I don't list my concern and question very clearly, it is my mistake and I apologize for it.
Let me show you more details:
1.int main()
2.{
3. int i;
4.
5. for (i = 0; i < 256; i++) {
6. }
7.}
; <label>:6: ; preds = %3
br label %7, !dbg !23
; <label>:7: ; preds = %6
%8 = load i32, i32* %2, align 4, !dbg !25
%9 = add nsw i32 %8, 1, !dbg !25
store i32 %9, i32* %2, align 4, !dbg !25
br label %3, !dbg !27, !llvm.loop !28
!23 = !DILocation(line: 6, column: 1, scope: !24)
You can see that this br instruction corresponds to right brace(i.e. line 6).
Let us see:
1.int main()
2.{
3. int i;
4.
5. for (i = 0; i < 256; i++) {
6. continue;
7. }
8. }
; <label>:6: ; preds = %3
br label %7, !dbg !23
; <label>:7: ; preds = %6
%8 = load i32, i32* %2, align 4, !dbg !25
%9 = add nsw i32 %8, 1, !dbg !25
store i32 %9, i32* %2, align 4, !dbg !25
br label %3, !dbg !27, !llvm.loop !28
!23 = !DILocation(line: 6, column: 1, scope: !24)
You can see that this br instruction corresponds to continue statement (i.e. line 6).
But, the result is: the first case line 6 right brace will not generated(it make sense and just group), but the latter case is line 6 continue and will generate location information for debugger. My question is they are the same but will be treated differently, I do not know how LLVM backend treat these two IR. Maybe I think these two cases are not related with Clang.
At 2017-06-03 22:45:11, "Marcin Słowik" <slowikmarcin1992 at gmail.com<mailto:slowikmarcin1992 at gmail.com>> wrote:
If i'm not mistaken, it is not a matter of LLVM IR nor LLVM backend, but rather LLVM frontend i.e. clang in this case.
Also, there is a slight semantic difference between those two cases:
`}` is not a statement. `continue` is.
In the first case, `br` does not correspond to the `}` itself, but rather to a natural BB termination.
In the latter, `br` explicitly corresponds to the `continue`.
If you still wonder what is the difference, look at the IR in the third case: without any braces. Where would you expect the debug information to be?
Cheers,
Marcin
2017-06-03 15:46 GMT+02:00 Frozen <bluechristlove at 163.com<mailto:bluechristlove at 163.com>>:
Hi Marcin:
I don't expect stop the right brace } and expect stop at continue keyword statement. My question is continue keyword statement is the same as right brace } statement in the LLVM IR except the !dbg!23 has different line number. I don't know how the LLVM backend distinguish it.
在 2017-06-03 19:20:46,"Marcin Słowik" <me at marandil.pl<mailto:me at marandil.pl>> 写道:
On Jun 3, 2017 9:48 AM, "Frozen via llvm-dev" <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
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?
Simply because continue keyword is a part of the AST, while '}' is not.
And you don't break on "natural" terminators. Also, would you expect a different behavior between:
for(i=0;i<N;++i)
doStuff();
And:
for(i=0;i<N;++i) {
doStuff();
}
While they should be identical on AST level?
Cheers,
Marcin
--
Marcin Słowik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170605/3e306a78/attachment-0001.html>
More information about the llvm-dev
mailing list