summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/loop-unrolling.cpp
diff options
context:
space:
mode:
authorHenry Wong <movietravelcode@outlook.com>2018-03-31 12:46:46 +0000
committerHenry Wong <movietravelcode@outlook.com>2018-03-31 12:46:46 +0000
commitf717d4795ac42bf51b52d9cbff70b7a85dbdd9bd (patch)
tree3c104742272ab4e753a9b48caf4509c670b6cdab /clang/test/Analysis/loop-unrolling.cpp
parent3b8ad346f99344f93ecda94e8327caa332c4b2a8 (diff)
downloadbcm5719-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/test/Analysis/loop-unrolling.cpp')
-rw-r--r--clang/test/Analysis/loop-unrolling.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/test/Analysis/loop-unrolling.cpp b/clang/test/Analysis/loop-unrolling.cpp
index aa145ac0af1..ce7ada8bd72 100644
--- a/clang/test/Analysis/loop-unrolling.cpp
+++ b/clang/test/Analysis/loop-unrolling.cpp
@@ -36,6 +36,29 @@ int simple_unroll2() {
return 0;
}
+int simple_unroll3_unsigned() {
+ int a[9];
+ int k = 42;
+ for (unsigned i = 0; i < 9; i++) {
+ clang_analyzer_numTimesReached(); // expected-warning {{9}}
+ a[i] = 42;
+ }
+ int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+ return 0;
+}
+
+int simple_unroll4_unsigned() {
+ int a[9];
+ int k = 42;
+ unsigned i;
+ for (i = (0); i < 9; i++) {
+ clang_analyzer_numTimesReached(); // expected-warning {{9}}
+ a[i] = 42;
+ }
+ int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+ return 0;
+}
+
int simple_no_unroll1() {
int a[9];
int k = 42;
OpenPOWER on IntegriCloud