diff options
| author | Henry Wong <movietravelcode@outlook.com> | 2018-03-31 12:46:46 +0000 |
|---|---|---|
| committer | Henry Wong <movietravelcode@outlook.com> | 2018-03-31 12:46:46 +0000 |
| commit | f717d4795ac42bf51b52d9cbff70b7a85dbdd9bd (patch) | |
| tree | 3c104742272ab4e753a9b48caf4509c670b6cdab /clang/lib/StaticAnalyzer | |
| parent | 3b8ad346f99344f93ecda94e8327caa332c4b2a8 (diff) | |
| download | bcm5719-llvm-f717d4795ac42bf51b52d9cbff70b7a85dbdd9bd.tar.gz bcm5719-llvm-f717d4795ac42bf51b52d9cbff70b7a85dbdd9bd.zip | |
[analyzer] Unroll the loop when it has a unsigned counter.
Summary:
The original implementation in the `LoopUnrolling.cpp` didn't consider the case where the counter is unsigned. This case is only handled in `simpleCondition()`, but this is not enough, we also need to deal with the unsinged counter with the counter initialization.
Since `IntegerLiteral` is `signed`, there is a `ImplicitCastExpr<IntegralCast>` in `unsigned counter = IntergerLiteral`. This patch add the `ignoringParenImpCasts()` in the `IntegerLiteral` matcher.
Reviewers: szepet, a.sidorin, NoQ, george.karpenkov
Reviewed By: szepet, george.karpenkov
Subscribers: xazax.hun, rnkovacs, cfe-commits, MTC
Differential Revision: https://reviews.llvm.org/D45086
llvm-svn: 328919
Diffstat (limited to 'clang/lib/StaticAnalyzer')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index b32e9348841..da4574c6151 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -141,13 +141,15 @@ static internal::Matcher<Stmt> forLoopMatcher() { return forStmt( hasCondition(simpleCondition("initVarName")), // Initialization should match the form: 'int i = 6' or 'i = 42'. - hasLoopInit(anyOf( - declStmt(hasSingleDecl(varDecl( - allOf(hasInitializer(integerLiteral().bind("initNum")), - equalsBoundNode("initVarName"))))), - binaryOperator(hasLHS(declRefExpr(to( - varDecl(equalsBoundNode("initVarName"))))), - hasRHS(integerLiteral().bind("initNum"))))), + hasLoopInit( + anyOf(declStmt(hasSingleDecl( + varDecl(allOf(hasInitializer(ignoringParenImpCasts( + integerLiteral().bind("initNum"))), + equalsBoundNode("initVarName"))))), + binaryOperator(hasLHS(declRefExpr(to(varDecl( + equalsBoundNode("initVarName"))))), + hasRHS(ignoringParenImpCasts( + integerLiteral().bind("initNum")))))), // Incrementation should be a simple increment or decrement // operator call. hasIncrement(unaryOperator( |

