Page MenuHomePhabricator

[Analyzer] Unroll for-loops where the upper boundary is a variable with know value
Needs ReviewPublic

Authored by baloghadamsoftware on Jun 13 2019, 9:11 AM.

Details

Summary

For-loops with a variable upper boundary do not differ very much from for-loops with integer literals if the value of the variable is known. Unroll these loops as well, similarly to them. This was a TODO anyway.

Diff Detail

Event Timeline

Szelethus added inline comments.Sat, Jul 6, 12:01 PM
lib/StaticAnalyzer/Core/LoopUnrolling.cpp
214–216

Alright, I stood on top of this for longer than I'd like to admit, what's happening here? Like, CondExpr, with the given testfile, should be i < n, right? Then BoundExpr is supposed to be i, and if that is equal to Matches[0].getNodeAs<Expr>("boundVarOperand") (which I guess is supposed to n), which I'm not sure how it could ever happen, we assign the RHS of the assignment to BoundExpr?

What does this do? Why is it needed? Which 2 test cases cover these lines?

221–230

I don't see obvious test case for which BoundNumVal would be unknown, am I wrong?

NoQ added inline comments.Tue, Jul 9, 12:34 PM
lib/StaticAnalyzer/Core/LoopUnrolling.cpp
214–216

I think this is about i < n vs. n > i.

221–230

We need an ExprInspection method that reliably produces an UnknownVal, because there's no truly valid reason to produce UnknownVal apart from "something is unimplemented".