diff options
author | Peter Szecsi <szepet95@gmail.com> | 2017-08-21 16:32:57 +0000 |
---|---|---|
committer | Peter Szecsi <szepet95@gmail.com> | 2017-08-21 16:32:57 +0000 |
commit | 3c3e1b0b54ceda8572e270cc02cb16c2e0c86163 (patch) | |
tree | 68da855be7da69bb737ef14c41c522452c521310 /clang/test/Analysis/loop-unrolling.cpp | |
parent | bf6c9bb84b75072bcbb60ce66b06082c427fcb29 (diff) | |
download | bcm5719-llvm-3c3e1b0b54ceda8572e270cc02cb16c2e0c86163.tar.gz bcm5719-llvm-3c3e1b0b54ceda8572e270cc02cb16c2e0c86163.zip |
[StaticAnalyzer] LoopUnrolling: Track a LoopStack in order to completely unroll specific loops
The LoopExit CFG information provides the opportunity to not mark the loops but
having a stack which tracks if a loop is unrolled or not. So in case of
simulating a loop we just add it and the information if it meets the
requirements to be unrolled to the top of the stack.
Differential Revision: https://reviews.llvm.org/D35684
llvm-svn: 311346
Diffstat (limited to 'clang/test/Analysis/loop-unrolling.cpp')
-rw-r--r-- | clang/test/Analysis/loop-unrolling.cpp | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/clang/test/Analysis/loop-unrolling.cpp b/clang/test/Analysis/loop-unrolling.cpp index 51261e3ee19..4d04b7b85b8 100644 --- a/clang/test/Analysis/loop-unrolling.cpp +++ b/clang/test/Analysis/loop-unrolling.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-max-loop 4 -analyzer-config unroll-loops=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 %s void clang_analyzer_numTimesReached(); @@ -219,3 +219,56 @@ int nested_inlined_no_unroll1() { int a = 22 / k; // no-warning return 0; } + + +int recursion_unroll1(bool b) { + int k = 2; + for (int i = 0; i < 5; i++) { + clang_analyzer_numTimesReached(); // expected-warning {{14}} + if(i == 0 && b) + recursion_unroll1(false); + clang_analyzer_numTimesReached(); // expected-warning {{15}} + } + int a = 22 / k; // no-warning + return 0; +} + +int recursion_unroll2(bool b) { + int k = 0; + for (int i = 0; i < 5; i++) { + clang_analyzer_numTimesReached(); // expected-warning {{10}} + if(i == 0 && b) + recursion_unroll2(false); + clang_analyzer_numTimesReached(); // expected-warning {{10}} + } + int a = 22 / k; // expected-warning {{Division by zero}} + return 0; +} + +int recursion_unroll3(bool b) { + int k = 2; + for (int i = 0; i < 5; i++) { + clang_analyzer_numTimesReached(); // expected-warning {{10}} + if(i == 4 && b) { + recursion_unroll3(false); + break; + } + clang_analyzer_numTimesReached(); // expected-warning {{10}} + } + int a = 22 / k; + return 0; +} + +int recursion_unroll4(bool b) { + int k = 2; + for (int i = 0; i < 5; i++) { + clang_analyzer_numTimesReached(); // expected-warning {{14}} + if(i == 0 && b) { + recursion_unroll4(false); + continue; + } + clang_analyzer_numTimesReached(); // expected-warning {{14}} + } + int a = 22 / k; + return 0; +} |