[PATCH] D62688: [Analyzer] Iterator Checkers - Model `empty()` method of containers
Sanaa82016 Najjar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 20 03:40:27 PDT 2019
sanaanajjar231288 added a comment.
In D62688#1549574 <https://reviews.llvm.org/D62688#1549574>, @Szelethus wrote:
> 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.
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