[PATCH] D41150: [CFG] Adding new CFGStmt LoopEntrance for the StaticAnalyzer
Artem Dergachev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 2 16:00:00 PST 2018
NoQ added a comment.
Because it wasn't immediately obvious to me how to apply both this patch and https://reviews.llvm.org/D39398 (there are a couple of minor conflicts between them), i wanted to post a few pictures for the reference, because `debug.ViewCFG` graphs are much easier to comprehend than text dumps.
For example, here's the new CFG for `check_return()` in `loopexit-cfg-output.cpp`:
833 int check_return() {
834 for (int i = 0; i < 10; i++) {
835 int j = 1;
836 while (j < 12) {
837 if (j % 2)
838 return 0;
839 }
840 }
841 return 1;
842 }
F5732587: Screen Shot 2018-01-02 at 3.42.17 PM.png <https://reviews.llvm.org/F5732587>
----
I essentially have one question at a glance - for loop counter variables, don't we want `LoopEntrance` be before the initialization? I.e. on this picture wouldn't it be better to have
[B8]
1: WhileStmt (LoopEntrance)
2: 1
3: int j = 1;
?
Because otherwise our future `LoopContext` wouldn't correspond to any variable's lifetime scope, so it'd be kind of useless as a `ScopeContext`. Because, as far as i understand, there are two scopes in every loop:
1. The scope of the whole loop which includes the counter,
2. The scope of every iteration, which goes out of scope after the iteration ends.
And currently `LoopContext` is none of these. Would loop unrolling still work in a sensible manner if we move `LoopEntrance` to the beginning of the block?
https://reviews.llvm.org/D41150
More information about the cfe-commits
mailing list