[PATCH] D62688: [Analyzer] Iterator Checkers - Model `empty()` method of containers

Kristóf Umann via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 18:53:58 PDT 2019


Szelethus added a comment.

Hmm, an idea just popped into my head. I'm not sure whether we have a single checker that does so much complicated (and totally awesome) modeling as `IteratorChecker`.  What do you think about a debug checker similar to `debug.ExprInspection`, like `debug.IteratorInspection`?

  // RUN: %clang_analyzer_cc1 -analyzer-checker=core,debug.IteratorInspection
  
  template <class Cont>
  void clang_analyzer_container_size(const Cont &);
  
  template <class It, class Cont>
  void clang_analyzer_is_attached_to_container(const It &, const Cont &);
  
  void non_empty1(const std::vector<int> &V) {
    assert(!V.empty());
    for (auto n: V) {}
    clang_analyzer_container_size(V); // expected-warning{{[1, intmax]}}
  }
  
  void non_empty2(const std::vector<int> &V) {
    for (auto n: V) {}
    assert(V.empty());
    clang_analyzer_container_size(V); // expected-warning{{[0, 0]}}
  }
  
  void foo(std::vector<int> v1, std::vector<int> v2) {
    clang_analyzer_is_attached_to_container(v1.begin(), v2); // expected-warning{{FALSE}}
  }

etc etc.



================
Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:714
 
     if (const auto *InstCall = dyn_cast<CXXInstanceCall>(&Call)) {
       if (isBeginCall(Func)) {
----------------
We seem to retrieve the `CXXInstanceCall` here too?


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62688/new/

https://reviews.llvm.org/D62688





More information about the cfe-commits mailing list