Adding escape check for the counter variable of the loop.
It is achieved by jumping back on the ExplodedGraph to its declStmt.
When the analyzer encounters a Stmt which can result pointer escape then we not considering unrolling the given loop.
Details
- Reviewers
NoQ dcoughlin zaks.anna xazax.hun - Commits
- rG8de103f2f0aa: [StaticAnalyzer] LoopUnrolling: Exclude cases where the counter is escaped…
rC311234: [StaticAnalyzer] LoopUnrolling: Exclude cases where the counter is escaped…
rL311234: [StaticAnalyzer] LoopUnrolling: Exclude cases where the counter is escaped…
Diff Detail
Event Timeline
Hmm, what prevents us from reusing existing matchers against S in isPossiblyEscaped()? Also i'd probably prefer to avoid recursion (we don't want stack traces of 225k frames).
Otherwise looks great, this should work!
Because I was not sure about the implementation detail of that. I dont want to write duplicated code so I tried to come up with a solution that the parameter of the matchers could be llvm::PointerUnion<const Decl *, const char *>. So I could define an equalsNode function which seems something like this: static internal::Matcher<Decl> equalsNode(llvm::PointerUnion<const Decl *, const char *> PU){..} and returns the suitable matcher and this could be used by the other matchers. However, PointerUnion does not let me to store char*. (This triggers the following assert in /home/Project/gsoc/llvm/include/llvm/ADT/PointerIntPair.h :
static_assert(IntBits <= PtrTraits::NumLowBitsAvailable, ,"PointerIntPair with integer size too large for pointer");)
I could use a simple union and an enum value as parameter but if you have better idea or know how to use PointerUnion correctly in this case please let me know!
Maybe use decl matcher as the parameter, and pass either equalsNode(Foo) or equalsBoundNode("foo") as argument value?
Good idea, thanks!
Using matchers to identify possible escape stmts.
Test cases updated.
Yay, looks cool.
lib/StaticAnalyzer/Core/LoopUnrolling.cpp | ||
---|---|---|
49 | Maybe check here that the counter variable is local? Or in isPossiblyEscaped(). Because globals are always escaped. | |
53 | Can we use the same trick with decl matcher here and in hasSuspiciousStmt(), for consistency? I suspect it'd even be nicer. | |
70 | Suggesting VarNodeMatcher as parameter name. EqualityCheck makes me imagine something that involves == or !=. |
Maybe check here that the counter variable is local?
Or in isPossiblyEscaped(). Because globals are always escaped.