diff options
author | Adam Balogh <adam.balogh@ericsson.com> | 2019-11-08 08:56:31 +0100 |
---|---|---|
committer | Adam Balogh <adam.balogh@ericsson.com> | 2019-11-08 08:59:50 +0100 |
commit | 0f88caeef8f2d4708f442d03db7723396712a143 (patch) | |
tree | 6d5d5e0b276c56443eaf87a63c36ad6daa1cbe2a /clang/test/Analysis/debug-iterator-modeling.cpp | |
parent | 7b9f5401a61646f584249012de0be27ee0cb2b9b (diff) | |
download | bcm5719-llvm-0f88caeef8f2d4708f442d03db7723396712a143.tar.gz bcm5719-llvm-0f88caeef8f2d4708f442d03db7723396712a143.zip |
[Analyzer] Checker for Debugging Iterator Checkers
For white-box testing correct container and iterator modelling it is essential
to access the internal data structures stored for container and iterators. This
patch introduces a simple debug checkers called debug.IteratorDebugging to
achieve this.
Differential Revision: https://reviews.llvm.org/D67156
Diffstat (limited to 'clang/test/Analysis/debug-iterator-modeling.cpp')
-rw-r--r-- | clang/test/Analysis/debug-iterator-modeling.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/clang/test/Analysis/debug-iterator-modeling.cpp b/clang/test/Analysis/debug-iterator-modeling.cpp new file mode 100644 index 00000000000..00816c80c66 --- /dev/null +++ b/clang/test/Analysis/debug-iterator-modeling.cpp @@ -0,0 +1,61 @@ +// RUN: %clang_analyze_cc1 -std=c++11\ +// RUN: -analyzer-checker=core,cplusplus\ +// RUN: -analyzer-checker=debug.DebugIteratorModeling,debug.ExprInspection\ +// RUN: -analyzer-config aggressive-binary-operation-simplification=true\ +// RUN: -analyzer-config c++-container-inlining=false %s -verify + +// RUN: %clang_analyze_cc1 -std=c++11\ +// RUN: -analyzer-checker=core,cplusplus\ +// RUN: -analyzer-checker=debug.DebugIteratorModeling,debug.ExprInspection\ +// RUN: -analyzer-config aggressive-binary-operation-simplification=true\ +// RUN: -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify + +#include "Inputs/system-header-simulator-cxx.h" + +template <typename Container> +long clang_analyzer_container_begin(const Container&); +template <typename Container> +long clang_analyzer_container_end(const Container&); +template <typename Iterator> +long clang_analyzer_iterator_position(const Iterator&); +template <typename Iterator> +void* clang_analyzer_iterator_container(const Iterator&); +template <typename Iterator> +bool clang_analyzer_iterator_validity(const Iterator&); +void clang_analyzer_denote(long, const char*); +void clang_analyzer_express(long); +void clang_analyzer_dump(const void*); +void clang_analyzer_eval(bool); + +void iterator_position(const std::vector<int> v0) { + auto b0 = v0.begin(), e0 = v0.end(); + + clang_analyzer_denote(clang_analyzer_iterator_position(b0), "$b0"); + clang_analyzer_denote(clang_analyzer_iterator_position(e0), "$e0"); + + clang_analyzer_express(clang_analyzer_iterator_position(b0)); // expected-warning{{$b0}} + clang_analyzer_express(clang_analyzer_iterator_position(e0)); // expected-warning{{$e0}} + + clang_analyzer_express(clang_analyzer_container_begin(v0)); // expected-warning{{$b0}} + clang_analyzer_express(clang_analyzer_container_end(v0)); // expected-warning{{$e0}} + + ++b0; + + clang_analyzer_express(clang_analyzer_iterator_position(b0)); // expected-warning{{$b0 + 1}} +} + +void iterator_container(const std::vector<int> v0) { + auto b0 = v0.begin(); + + clang_analyzer_dump(&v0); //expected-warning{{&v0}} + clang_analyzer_eval(clang_analyzer_iterator_container(b0) == &v0); // expected-warning{{TRUE}} +} + +void iterator_validity(std::vector<int> v0) { + auto b0 = v0.begin(); + clang_analyzer_eval(clang_analyzer_iterator_validity(b0)); //expected-warning{{TRUE}} + + v0.clear(); + + clang_analyzer_eval(clang_analyzer_iterator_validity(b0)); //expected-warning{{FALSE}} +} |