1 // RUN: %clang_analyze_cc1 -std=c++11\ 2 // RUN: -analyzer-checker=core,cplusplus\ 3 // RUN: -analyzer-checker=debug.DebugIteratorModeling,debug.ExprInspection\ 4 // RUN: -analyzer-config aggressive-binary-operation-simplification=true\ 5 // RUN: -analyzer-config c++-container-inlining=false %s -verify 6 7 // RUN: %clang_analyze_cc1 -std=c++11\ 8 // RUN: -analyzer-checker=core,cplusplus\ 9 // RUN: -analyzer-checker=debug.DebugIteratorModeling,debug.ExprInspection\ 10 // RUN: -analyzer-config aggressive-binary-operation-simplification=true\ 11 // RUN: -analyzer-config c++-container-inlining=true -DINLINE=1 %s -verify 12 13 #include "Inputs/system-header-simulator-cxx.h" 14 15 template <typename Container> 16 long clang_analyzer_container_begin(const Container&); 17 template <typename Container> 18 long clang_analyzer_container_end(const Container&); 19 template <typename Iterator> 20 long clang_analyzer_iterator_position(const Iterator&); 21 template <typename Iterator> 22 void* clang_analyzer_iterator_container(const Iterator&); 23 template <typename Iterator> 24 bool clang_analyzer_iterator_validity(const Iterator&); 25 void clang_analyzer_denote(long, const char*); 26 void clang_analyzer_express(long); 27 void clang_analyzer_dump(const void*); 28 void clang_analyzer_eval(bool); 29 iterator_position(const std::vector<int> v0)30void iterator_position(const std::vector<int> v0) { 31 auto b0 = v0.begin(), e0 = v0.end(); 32 33 clang_analyzer_denote(clang_analyzer_container_begin(v0), "$b0"); 34 clang_analyzer_denote(clang_analyzer_container_end(v0), "$e0"); 35 36 clang_analyzer_express(clang_analyzer_iterator_position(b0)); // expected-warning{{$b0}} 37 clang_analyzer_express(clang_analyzer_iterator_position(e0)); // expected-warning{{$e0}} 38 39 ++b0; 40 41 clang_analyzer_express(clang_analyzer_iterator_position(b0)); // expected-warning{{$b0 + 1}} 42 } 43 iterator_container(const std::vector<int> v0)44void iterator_container(const std::vector<int> v0) { 45 auto b0 = v0.begin(); 46 47 clang_analyzer_dump(&v0); //expected-warning{{&v0}} 48 clang_analyzer_eval(clang_analyzer_iterator_container(b0) == &v0); // expected-warning{{TRUE}} 49 } 50 iterator_validity(std::vector<int> v0)51void iterator_validity(std::vector<int> v0) { 52 auto b0 = v0.begin(); 53 clang_analyzer_eval(clang_analyzer_iterator_validity(b0)); //expected-warning{{TRUE}} 54 55 v0.clear(); 56 57 clang_analyzer_eval(clang_analyzer_iterator_validity(b0)); //expected-warning{{FALSE}} 58 } 59