[PATCH] D32906: [Analyzer] Iterator Checker - Part 10: Support for iterators passed as parameter

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 6 00:19:43 PDT 2018


baloghadamsoftware updated this revision to Diff 164152.
baloghadamsoftware added a comment.

Modification of the checker not needed anymore. Only tests added.


https://reviews.llvm.org/D32906

Files:
  test/Analysis/iterator-range.cpp
  test/Analysis/mismatched-iterator.cpp


Index: test/Analysis/mismatched-iterator.cpp
===================================================================
--- test/Analysis/mismatched-iterator.cpp
+++ test/Analysis/mismatched-iterator.cpp
@@ -144,6 +144,19 @@
   v1.insert(i, n); // expected-warning{{Container accessed using foreign iterator argument}}
 }
 
+template<typename Container, typename Iterator>
+bool is_cend(Container cont, Iterator it) {
+  return it == cont.cend();
+}
+
+void good_empty(std::vector<int> &v) {
+  is_cend(v, v.cbegin()); // no-warning
+}
+
+void bad_empty(std::vector<int> &v1, std::vector<int> &v2) {
+  is_cend(v1, v2.cbegin()); // expected-warning at 149{{Iterators of different containers used where the same container is expected}}
+}
+
 void good_move(std::vector<int> &v1, std::vector<int> &v2) {
   const auto i0 = ++v2.cbegin();
   v1 = std::move(v2);
Index: test/Analysis/iterator-range.cpp
===================================================================
--- test/Analysis/iterator-range.cpp
+++ test/Analysis/iterator-range.cpp
@@ -216,6 +216,11 @@
     *first; // no-warning
 }
 
+void bad_non_std_find(std::vector<int> &V, int e) {
+  auto first = nonStdFind(V.begin(), V.end(), e);
+  *first; // expected-warning{{Iterator accessed outside of its range}}
+}
+
 void tricky(std::vector<int> &V, int e) {
   const auto first = V.begin();
   const auto comp1 = (first != V.end()), comp2 = (first == V.end());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32906.164152.patch
Type: text/x-patch
Size: 1412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180906/80473f4c/attachment-0001.bin>


More information about the cfe-commits mailing list