[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
flovent wrote: @steakhal Thank you for review! I forgot to mention that the testcases added is copied from their non-range verison since they have same effect to iterator which mentioned in PR description, the only change is the method's name and a parameter named `vec` in test function to simulate `range`. so the `Design decision` part is completely copied from original testcase. but it does seems that the problem you mentioned is suspicious, i will take a look on them and see what happens after i change it(like add commented lines back). https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -1139,6 +1289,271 @@ void deque_insert_end(std::deque &D, int n) { // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1 } +/// insert_range() +/// +/// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator +///ahead of the insertion point are decremented; if the +///relation between the insertion point and the first +///position of the container is known, the first position +///of the container is also decremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_insert_range_begin(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + auto i2 = L.insert_range(i0, vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1 steakhal wrote: Why is this line disabled? We could (and should) expect the actual output; and put a FIXME there if it's actually not what is desired. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/flovent edited https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the +/// past-the-end position of the container is incremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_append_range(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + L.append_range(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$ + clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$ FIXME: Should be $L.end() + 1 flovent wrote: This message is not from the initialization statement of this iterator, ContainerModeling deal `cbegin` and `begin` or the corresponding iterator the same way, this is the function used to determine if this function returns container's first iterator. ``` bool isBeginCall(const FunctionDecl *Func) { const auto *IdInfo = Func->getIdentifier(); if (!IdInfo) return false; return IdInfo->getName().ends_with_insensitive("begin"); } ``` And this message seems to be just for test and will not show for user, `$L.end()` is setted in previous line: ``` clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); ``` https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/flovent edited https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/flovent edited https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -1139,6 +1289,271 @@ void deque_insert_end(std::deque &D, int n) { // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1 } +/// insert_range() +/// +/// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator +///ahead of the insertion point are decremented; if the +///relation between the insertion point and the first +///position of the container is known, the first position +///of the container is also decremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_insert_range_begin(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + auto i2 = L.insert_range(i0, vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1 + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$ +} + +void list_insert_range_behind_begin(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + auto i3 = L.insert_range(i1, vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ FIXME: Should be $L.begin() - 1 + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$ + // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() flovent wrote: These check lines is disabled because currently `ContainerModeling` doesn't model these function's return value like `insert`, this checker only models impact for container now except `begin`(`cbegin`) and `end`(`cend`) call https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the +/// past-the-end position of the container is incremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_append_range(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + L.append_range(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$ + clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$ FIXME: Should be $L.end() + 1 +} + +/// std::vector-like containers: The past-the-end iterator is invalidated. + +void vector_append_range(std::vector &V, std::vector& vec) { + auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()"); + + V.emplace_back(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$ flovent wrote: ``` clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$ ``` I add this in my local environment, it can pass the test, and it's missed in non-range version test function, so i think it's not intentional. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -1139,6 +1289,271 @@ void deque_insert_end(std::deque &D, int n) { // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $D.end() - 1 } +/// insert_range() +/// +/// - Design decision: shifts positions to the <-LEFT<- (i.e. all iterator +///ahead of the insertion point are decremented; if the +///relation between the insertion point and the first +///position of the container is known, the first position +///of the container is also decremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_insert_range_begin(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + auto i2 = L.insert_range(i0, vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $L.begin() - 1 + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end(){{$ +} + +void list_insert_range_behind_begin(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = ++L.cbegin(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + auto i3 = L.insert_range(i1, vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ FIXME: Should be $L.begin() - 1 + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.begin() + 1{{$ + // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.begin() steakhal wrote: Same here. We should not have disabled check lines. This applies to all of the currently disabled lines. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the steakhal wrote: +1 https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the +/// past-the-end position of the container is incremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_append_range(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + L.append_range(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$ + clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$ FIXME: Should be $L.end() + 1 steakhal wrote: Why should this be `$L.end() + 1`? `i2` was defined by `L.cend()`, so I think the actual output is correct. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/steakhal requested changes to this pull request. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the +/// past-the-end position of the container is incremented). +/// +/// - Iterator invalidation rules depend the container type. + +/// std::list-like containers: No iterators are invalidated. + +void list_append_range(std::list &L, std::vector& vec) { + auto i0 = L.cbegin(), i1 = --L.cend(), i2 = L.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(L), "$L.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(L), "$L.end()"); + + L.append_range(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{TRUE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$L.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$L.end() - 1{{$ + clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning-re {{$L.end(){{$ FIXME: Should be $L.end() + 1 +} + +/// std::vector-like containers: The past-the-end iterator is invalidated. + +void vector_append_range(std::vector &V, std::vector& vec) { + auto i0 = V.cbegin(), i1 = --V.cend(), i2 = V.cend(); + + clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()"); + clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()"); + + V.emplace_back(vec); + + clang_analyzer_eval(clang_analyzer_iterator_validity(i0)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{TRUE}} + clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} + + clang_analyzer_express(clang_analyzer_iterator_position(i0)); // expected-warning-re {{$V.begin(){{$ + clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning-re {{$V.end() - 1{{$ steakhal wrote: `clang_analyzer_express(clang_analyzer_iterator_position(i2));` is not checked here; intentional? https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
flovent wrote: thank you! I will wait for other reviewer's approval. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/NagyDonat approved this pull request. Well, I have to admit that I'm not familiar with this checker -- my recent change is just part of a semi-automated commit series that mechanically changed the same trivial thing in many checkers. However, your change appears to be straightforward and well-tested, so I'm giving a tentative approval. I also added a few other reviewers, so please wait with merging it for a few days or until somebody else approves this change. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/NagyDonat edited https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
@@ -635,6 +668,66 @@ void deque_emplace_back(std::deque &D, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i2)); //expected-warning{{FALSE}} } +/// append_range() +/// +/// - Design decision: extends containers to the ->RIGHT-> (i.e. the NagyDonat wrote: I don't understand what does `Design decision:` mean in this context (is it some weird boilerplate from a rigid test-driven design pattern??), but it's consistently applied in all other test blocks, so it's probably better to use it here. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
flovent wrote: @NagyDonat Hi, sorry to bother, can you review this PR? i don't have access to request review and i see that the last commit of this checker is submitted by you. https://github.com/llvm/llvm-project/pull/129719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling (PR #129719)
https://github.com/flovent updated https://github.com/llvm/llvm-project/pull/129719 >From 90da509c1955afb925f880db2e3cbfdac0311095 Mon Sep 17 00:00:00 2001 From: flovent Date: Tue, 4 Mar 2025 22:54:10 +0800 Subject: [PATCH 1/2] [clang][analyzer] Add support for C++23 container methods releated to iterator in ContainerModeling --- .../Checkers/ContainerModeling.cpp| 6 + .../Inputs/system-header-simulator-cxx.h | 42 ++ clang/test/Analysis/iterator-modeling.cpp | 480 +- 3 files changed, 527 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp index 55ed809bfed6c..04e7696ed5b9d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp @@ -74,19 +74,25 @@ class ContainerModeling CallDescriptionMap NoIterParamFunctions = { {{CDM::CXXMethod, {"clear"}, 0}, &ContainerModeling::handleClear}, {{CDM::CXXMethod, {"assign"}, 2}, &ContainerModeling::handleAssign}, + {{CDM::CXXMethod, {"assign_range"}, 1}, &ContainerModeling::handleAssign}, {{CDM::CXXMethod, {"push_back"}, 1}, &ContainerModeling::handlePushBack}, {{CDM::CXXMethod, {"emplace_back"}, 1}, &ContainerModeling::handlePushBack}, + {{CDM::CXXMethod, {"append_range"}, 1}, + &ContainerModeling::handlePushBack}, {{CDM::CXXMethod, {"pop_back"}, 0}, &ContainerModeling::handlePopBack}, {{CDM::CXXMethod, {"push_front"}, 1}, &ContainerModeling::handlePushFront}, {{CDM::CXXMethod, {"emplace_front"}, 1}, &ContainerModeling::handlePushFront}, + {{CDM::CXXMethod, {"prepend_range"}, 1}, + &ContainerModeling::handlePushFront}, {{CDM::CXXMethod, {"pop_front"}, 0}, &ContainerModeling::handlePopFront}, }; CallDescriptionMap OneIterParamFunctions = { {{CDM::CXXMethod, {"insert"}, 2}, &ContainerModeling::handleInsert}, + {{CDM::CXXMethod, {"insert_range"}, 2}, &ContainerModeling::handleInsert}, {{CDM::CXXMethod, {"emplace"}, 2}, &ContainerModeling::handleInsert}, {{CDM::CXXMethod, {"erase"}, 1}, &ContainerModeling::handleErase}, {{CDM::CXXMethod, {"erase_after"}, 1}, diff --git a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h index a379a47515668..5a42a952cca85 100644 --- a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h +++ b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h @@ -336,6 +336,15 @@ namespace std { iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); +template +void assign_range(R&& rg); + +template +iterator insert_range(const_iterator position, R&& rg); + +template +void append_range(R&& rg); + T &operator[](size_t n) { return _start[n]; } @@ -414,6 +423,18 @@ namespace std { iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); +template +void assign_range(R&& rg); + +template +iterator insert_range(const_iterator position, R&& rg); + +template +void append_range(R&& rg); + +template +void prepend_range(R&& rg); + iterator begin() { return iterator(_start); } const_iterator begin() const { return const_iterator(_start); } const_iterator cbegin() const { return const_iterator(_start); } @@ -488,6 +509,18 @@ namespace std { iterator erase(const_iterator position); iterator erase(const_iterator first, const_iterator last); +template +void assign_range(R&& rg); + +template +iterator insert_range(const_iterator position, R&& rg); + +template +void append_range(R&& rg); + +template +void prepend_range(R&& rg); + T &operator[](size_t n) { return _start[n]; } @@ -561,6 +594,15 @@ namespace std { iterator erase_after(const_iterator position); iterator erase_after(const_iterator first, const_iterator last); +template +void assign_range(R&& rg); + +template +void prepend_range(R&& rg); + +template +iterator insert_range_after(const_iterator pos, R&& rg); + iterator begin() { return iterator(_start); } const_iterator begin() const { return const_iterator(_start); } const_iterator cbegin() const { return const_iterator(_start); } diff --git a/clang/test/Analysis/iterator-modeling.cpp b/clang/test/Analysis/iterator-modeling.cpp index 78882da4431fd..a5be1666f1bed 100644 --- a/clang/test/Analysis/iterator-modeling.cpp +++ b/clang/test/Analysis/iterator-modeling.cpp @@ -482,6 +482,39 @@ void forward_list_assign(std::forward_list &FL, int n) { clang_analyzer_eval(clang_analyzer_iterator_validity(i1)); //expected-warning{{FALSE}} } +/// assign_range() +/// +/// - Invalidates all iterators, including the pa