[Soot-list] Distinguishing between if and while loops
Eric Bodden
eric.bodden at uni-paderborn.de
Mon Aug 12 04:51:55 EDT 2019
Helki,
> To distinguish loops from if statements, I am doing the following steps:
> 1. I am using LoopFinder to find all the loops in a file and storing them in a list.
> 2. If I encounter an 'if' statement, I check if it is the head of any of the loops in my list.
> 3. If it is, then its a loop, otherwise its an 'if' statement.
This sounds quite sensible.
> But, the above method does not accomodate the case when the loop head is not the predicate statement but some preparatory statement. For example, this loop: for(int i = 0; i<Sample.f3; i++) {} is converted into the following:
>
> label7:
> i = i + 1;
>
> label8:
> $i2 = <Sample: int f3>;
>
> if i < $i2 goto label7;
>
> and the loop head is not a predicate statement. How do I handle such cases? If I start going inside loop bodies to check for the predicate statements, the analysis might encounter a genuine 'if' statement inside the loop and classify as a loop.
> Is it okay if I check only the first statement of the loop body if the loop header is not a predicate statement?
I think you should be able to use https://www.sable.mcgill.ca/soot/doc/soot/jimple/toolkits/annotation/logic/Loop.html#getBackJumpStmt()
I personally think that then you should be able to cover all cases - but I have not conducted a formal proof.
Cheers
Eric
More information about the Soot-list
mailing list