diff options
Diffstat (limited to 'test/Analysis/loop-unrolling.cpp')
-rw-r--r-- | test/Analysis/loop-unrolling.cpp | 144 |
1 files changed, 132 insertions, 12 deletions
diff --git a/test/Analysis/loop-unrolling.cpp b/test/Analysis/loop-unrolling.cpp index 844d1f18ea578..b7375df38b695 100644 --- a/test/Analysis/loop-unrolling.cpp +++ b/test/Analysis/loop-unrolling.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++11 %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++11 -analyzer-config exploration_strategy=unexplored_first_queue %s +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify -std=c++11 -DDFS=1 %s void clang_analyzer_numTimesReached(); void clang_analyzer_warnIfReached(); @@ -35,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; @@ -98,13 +122,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; @@ -114,7 +226,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; } } @@ -126,7 +238,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. @@ -184,7 +296,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; } @@ -234,7 +346,11 @@ int simple_known_bound_loop() { int simple_unknown_bound_loop() { for (int i = 2; i < getNum(); i++) { +#ifdef DFS clang_analyzer_numTimesReached(); // expected-warning {{10}} +#else + clang_analyzer_numTimesReached(); // expected-warning {{13}} +#endif } return 0; } @@ -252,7 +368,11 @@ int nested_inlined_unroll1() { int nested_inlined_no_unroll1() { int k; for (int i = 0; i < 9; i++) { +#ifdef ANALYZER_CM_Z3 + clang_analyzer_numTimesReached(); // expected-warning {{13}} +#else clang_analyzer_numTimesReached(); // expected-warning {{15}} +#endif k = simple_unknown_bound_loop(); // reevaluation without inlining, splits the state as well } int a = 22 / k; // no-warning @@ -263,8 +383,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}} } @@ -276,7 +396,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}} } @@ -302,7 +422,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; } |