r328619 - [analyzer] LoopUnrolling: update the matched assignment operators

Peter Szecsi via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 27 05:16:56 PDT 2018


Author: szepet
Date: Tue Mar 27 05:16:56 2018
New Revision: 328619

URL: http://llvm.org/viewvc/llvm-project?rev=328619&view=rev
Log:
[analyzer] LoopUnrolling: update the matched assignment operators

Extended the matched assignment operators when checking for bound changes in a body of the loop by using the freshly added isAssignmentOperator matcher.
This covers all the (current) possible assignments, tests added as well.

Differential Revision: https://reviews.llvm.org/D38921


Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
    cfe/trunk/test/Analysis/loop-unrolling.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp?rev=328619&r1=328618&r2=328619&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/LoopUnrolling.cpp Tue Mar 27 05:16:56 2018
@@ -97,9 +97,7 @@ changeIntBoundNode(internal::Matcher<Dec
       unaryOperator(anyOf(hasOperatorName("--"), hasOperatorName("++")),
                     hasUnaryOperand(ignoringParenImpCasts(
                         declRefExpr(to(varDecl(VarNodeMatcher)))))),
-      binaryOperator(anyOf(hasOperatorName("="), hasOperatorName("+="),
-                           hasOperatorName("/="), hasOperatorName("*="),
-                           hasOperatorName("-=")),
+      binaryOperator(isAssignmentOperator(),
                      hasLHS(ignoringParenImpCasts(
                          declRefExpr(to(varDecl(VarNodeMatcher)))))));
 }

Modified: cfe/trunk/test/Analysis/loop-unrolling.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/loop-unrolling.cpp?rev=328619&r1=328618&r2=328619&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/loop-unrolling.cpp (original)
+++ cfe/trunk/test/Analysis/loop-unrolling.cpp Tue Mar 27 05:16:56 2018
@@ -99,13 +99,101 @@ int simple_no_unroll5() {
   return 0;
 }
 
+int no_unroll_assignment() {
+  for (int i = 0; i < 9; i++) {
+    i = i + 1;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment2() {
+  for (int i = 0; i < 9; i++) {
+    i *= 2;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment3() {
+  for (int i = 128; i > 0; i--) {
+    i /= 2;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment4() {
+  for (int i = 0; i < 9; i++) {
+    i -= 2;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment5() {
+  for (int i = 0; i < 9; i++) {
+    i += 1;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment6() {
+  for (int i = 128; i > 0; i--) {
+    i >>= 1;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment7() {
+  for (int i = 0; i < 512; i++) {
+    i <<= 1;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment8() {
+  for (int i = 0; i < 9; i++) {
+    i %= 8;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment9() {
+  for (int i = 0; i < 9; i++) {
+    i &= 31;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment10() {
+  for (int i = 0; i < 9; i++) {
+    i |= 2;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
+int no_unroll_assignment11() {
+  for (int i = 0; i < 9; i++) {
+    i ^= 2;
+    clang_analyzer_numTimesReached(); // expected-warning {{4}}
+  }
+  return 0;
+}
+
 int make_new_branches_loop_cached() {
   for (int i = 0; i < 8; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{4}}
-    if(getNum()){
-        (void) i; // Since this Stmt does not change the State the analyzer
-                  // won't make a new execution path but reuse the earlier nodes.
-      }
+    if (getNum()) {
+      (void)i; // Since this Stmt does not change the State the analyzer
+               // won't make a new execution path but reuse the earlier nodes.
+    }
   }
   clang_analyzer_warnIfReached(); // no-warning
   return 0;
@@ -115,7 +203,7 @@ int make_new_branches_loop_uncached() {
   int l = 2;
   for (int i = 0; i < 8; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{10}}
-    if(getNum()){
+    if (getNum()) {
       ++l;
     }
   }
@@ -127,7 +215,7 @@ int make_new_branches_loop_uncached2() {
   int l = 2;
   for (int i = 0; i < 8; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{10}}
-    if(getNum()){
+    if (getNum()) {
       ++l;
     }
     (void)&i; // This ensures that the loop won't be unrolled.
@@ -185,7 +273,7 @@ int nested_outer_unrolled() {
     for (j = 0; j < 9; ++j) {
       clang_analyzer_numTimesReached(); // expected-warning {{4}}
       a[j] = 22;
-      (void) &j; // ensures that the inner loop won't be unrolled
+      (void)&j; // ensures that the inner loop won't be unrolled
     }
     a[i] = 42;
   }
@@ -268,8 +356,8 @@ int recursion_unroll1(bool b) {
   int k = 2;
   for (int i = 0; i < 5; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{13}}
-    if(i == 0 && b) // Splits the state in the first iteration but the recursion
-                    // call will be unrolled anyway since the condition is known there.
+    if (i == 0 && b)                  // Splits the state in the first iteration but the recursion
+                                      // call will be unrolled anyway since the condition is known there.
       recursion_unroll1(false);
     clang_analyzer_numTimesReached(); // expected-warning {{14}}
   }
@@ -281,7 +369,7 @@ int recursion_unroll2(bool b) {
   int k = 0;
   for (int i = 0; i < 5; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{9}}
-    if(i == 0 && b)
+    if (i == 0 && b)
       recursion_unroll2(false);
     clang_analyzer_numTimesReached(); // expected-warning {{9}}
   }
@@ -307,7 +395,7 @@ int recursion_unroll4(bool b) {
   int k = 2;
   for (int i = 0; i < 5; i++) {
     clang_analyzer_numTimesReached(); // expected-warning {{13}}
-    if(i == 0 && b) {
+    if (i == 0 && b) {
       recursion_unroll4(false);
       continue;
     }




More information about the cfe-commits mailing list