← Back to Pull requests

[libc++] Assert that erase and extract are not passed end() in the associative containers #232661

Open
ilyas-mallah opened this pull request with 338 lines diff across 10 files
View on GitHub
ilyas-mallah ilyas-mallah commented on Oct 16, 2026 10:04 UTC
Author

erase(end()) and extract(end()) on map, multimap, set and multiset treat the end node as an element and crash with a SIGSEGV in the fast mode. m.erase(m.find(k)) with a missing key is one easy way to get there. On the unordered containers, extract(end()) reads through a null node.

This adds the __p != end() assertion that __hash_table::erase already has to erase in __tree and to extract in both. A range erase that runs past end() now traps too, since it loops over the single-iterator erase.

The tests cover erase and extract with end() on all eight containers, including the unordered erase check, which had no hardening test.

AI usage: Claude Code helped with the test runs and test scaffolding. I traced the issue, made the fix, and validated every change.

Diff: 338 lines (+338 / -0) across 10 files Reviewer: ldionne Review duration: 71099m
All Vouch review confidence checks passed
Residual risk 0.07 = Change Risk (0.63) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.63 · 338 lines diff across 10 files
0.63
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
89%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.349
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
12 items
ilyas-mallah ilyas-mallah commented on Oct 16, 2026 10:04 UTC
Author

@philnik777

github-actions[bot] github-actions[bot] commented on Oct 16, 2026 10:04 UTC
Bot

<!--LLVM NEW CONTRIBUTOR COMMENT-->

Hello @ilyas-mallah :wave:

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.

  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.
  • Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.

    ---

    Frequently asked questions

    How do I add reviewers?

    This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

    You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

    What if there are no comments?

    If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

    Are any special GitHub settings required to contribute to LLVM?

    We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.

    ---

    If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

    Thank you,
    The LLVM Community

    llvmorg-github-actions[bot] llvmorg-github-actions[bot] commented on Oct 16, 2026 10:05 UTC
    Bot

    <!--LLVM PR SUMMARY COMMENT-->

    @llvm/pr-subscribers-libcxx

    Author: Ilyas Mallah (ilyas-mallah)

    <details>
    <summary>Changes</summary>

    erase(end()) and extract(end()) on map, multimap, set and multiset treat the end node as an element and crash with a SIGSEGV in the fast mode. m.erase(m.find(k)) with a missing key is one easy way to get there. On the unordered containers, extract(end()) reads through a null node.

    This adds the __p != end() assertion that __hash_table::erase already has to erase in __tree and to extract in both. A range erase that runs past end() now traps too, since it loops over the single-iterator erase.

    The tests cover erase and extract with end() on all eight containers, including the unordered erase check, which had no hardening test.

    AI usage: Claude Code helped with the test runs and test scaffolding. I traced the issue, made the fix, and validated every change.

    ---
    Full diff: https://github.com/llvm/llvm-project/pull/232661.diff

    8 Files Affected:

  • (modified) libcxx/include/__hash_table (+2)

  • (modified) libcxx/include/__tree (+4)

  • (added) libcxx/test/libcxx/containers/associative/map/assert.erase_extract.end.pass.cpp (+59)

  • (added) libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp (+61)

  • (added) libcxx/test/libcxx/containers/unord/unord.map/assert.erase_extract.end.pass.cpp (+41)

  • (added) libcxx/test/libcxx/containers/unord/unord.multimap/assert.erase_extract.end.pass.cpp (+41)

  • (added) libcxx/test/libcxx/containers/unord/unord.multiset/assert.erase_extract.end.pass.cpp (+42)

  • (added) libcxx/test/libcxx/containers/unord/unord.set/assert.erase_extract.end.pass.cpp (+42)
  • ``````

    diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table
    index 23916e3a3ecf32..c3df10b305488f 100644
    --- a/libcxx/include/__hash_table
    +++ b/libcxx/include/__hash_table
    @@ -1695,6 +1695,8 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(key_type const&
     template <class _Tp, class _Hash, class _Equal, class _Alloc>
     template <class _NodeHandle>
     _LIBCPP_HIDE_FROM_ABI _NodeHandle __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(const_iterator __p) {
    +  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
    +      __p != end(), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
       allocator_type __alloc(__node_alloc());
       return _NodeHandle(remove(__p).release(), __alloc);
     }
    diff --git a/libcxx/include/__tree b/libcxx/include/__tree
    index 7cfa8e86fdc028..8c977d74bd53af 100644
    --- a/libcxx/include/__tree
    +++ b/libcxx/include/__tree
    @@ -2133,6 +2133,8 @@ template <class _Tp, class _Compare, class _Allocator>
     template <class _NodeHandle>
     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX26 _NodeHandle
     __tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) {
    +  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
    +      __p != end(), "associative container::extract(iterator) called with a non-dereferenceable iterator");
       __node_pointer __np = __p.__get_np();
       __remove_node_pointer(__np);
       return _NodeHandle(__np, __alloc());
    @@ -2200,6 +2202,8 @@ __tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(__tree<_Tp, _Comp2,
     template <class _Tp, class _Compare, class _Allocator>
     _LIBCPP_CONSTEXPR_SINCE_CXX26
         typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) {
    +  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
    +      __p != end(), "associative container::erase(iterator) called with a non-dereferenceable iterator");
       __node_pointer __np    = __p.__get_np();
       iterator __r           = __remove_node_pointer(__np);
       __node_allocator& __na = __node_alloc();
    diff --git a/libcxx/test/libcxx/containers/associative/map/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/associative/map/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..c135643b88fa24
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/associative/map/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,59 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <map>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <map>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    std::map<int, int> c{{1, 1}, {2, 2}, {3, 3}};
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::map<int, int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::multimap<int, int> c{{1, 1}, {2, 2}, {3, 3}};
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::multimap<int, int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    diff --git a/libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..83ac0a69618508
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,61 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <set>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <set>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    int a[] = {1, 2, 3};
    +    std::set<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::set<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    int a[] = {1, 2, 3};
    +    std::multiset<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::multiset<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    diff --git a/libcxx/test/libcxx/containers/unord/unord.map/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.map/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..560621191b1bd1
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/unord/unord.map/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,41 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <unordered_map>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <unordered_map>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    std::unordered_map<int, int> c{{1, 1}, {2, 2}, {3, 3}};
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::unordered_map<int, int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    diff --git a/libcxx/test/libcxx/containers/unord/unord.multimap/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multimap/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..6ea3e3f04bd341
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/unord/unord.multimap/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,41 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <unordered_map>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <unordered_map>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    std::unordered_multimap<int, int> c{{1, 1}, {2, 2}, {3, 3}};
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::unordered_multimap<int, int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    diff --git a/libcxx/test/libcxx/containers/unord/unord.multiset/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.multiset/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..58c3c348e96243
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/unord/unord.multiset/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,42 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <unordered_set>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <unordered_set>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    int a[] = {1, 2, 3};
    +    std::unordered_multiset<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::unordered_multiset<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    diff --git a/libcxx/test/libcxx/containers/unord/unord.set/assert.erase_extract.end.pass.cpp b/libcxx/test/libcxx/containers/unord/unord.set/assert.erase_extract.end.pass.cpp
    new file mode 100644
    index 00000000000000..568aca8125af88
    --- /dev/null
    +++ b/libcxx/test/libcxx/containers/unord/unord.set/assert.erase_extract.end.pass.cpp
    @@ -0,0 +1,42 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <unordered_set>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <unordered_set>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    int a[] = {1, 2, 3};
    +    std::unordered_set<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "unordered container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::unordered_set<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "unordered container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  return 0;
    +}
    
    
    ``````

    </details>

    ldionne ldionne commented on Oct 21, 2026 20:40 UTC
    Contributor

    /libcxx-bot benchmark libcxx/test/benchmarks/containers/associative/map.bench.cpp libcxx/test/benchmarks/containers/associative/multimap.bench.cpp libcxx/test/benchmarks/containers/associative/multiset.bench.cpp libcxx/test/benchmarks/containers/associative/set.bench.cpp libcxx/test/benchmarks/containers/associative/unordered_map.bench.cpp libcxx/test/benchmarks/containers/associative/unordered_multimap.bench.cpp libcxx/test/benchmarks/containers/associative/unordered_multiset.bench.cpp libcxx/test/benchmarks/containers/associative/unordered_set.bench.cpp

    _Running benchmarks in https://github.com/llvm/llvm-project/actions/runs/39672355684_

    ldionne ldionne commented on code on Oct 21, 2026 20:43 UTC
    Code Review
    libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp:1
    @@ -0,0 +1,61 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <set>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <set>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    int a[] = {1, 2, 3};
    +    std::set<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::set<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    int a[] = {1, 2, 3};
    +    std::multiset<int> c(a, a + 3);

    Let's move these tests to libcxx/test/libcxx/containers/associative/multiset/assert.erase_extract.end.pass.cpp, and same for the multimap ones.

    ldionne ldionne requested changes on Oct 21, 2026 20:43 UTC
    Changes Requested Reviewer

    Requested changes.

    ldionne ldionne commented on Oct 21, 2026 20:43 UTC
    Contributor

    (Apart from that, this looks reasonable to me)

    ilyas-mallah ilyas-mallah commented on code on Oct 22, 2026 07:07 UTC
    Code Review
    libcxx/test/libcxx/containers/associative/set/assert.erase_extract.end.pass.cpp:1
    @@ -0,0 +1,61 @@
    +//===----------------------------------------------------------------------===//
    +//
    +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
    +// See https://llvm.org/LICENSE.txt for license information.
    +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
    +//
    +//===----------------------------------------------------------------------===//
    +
    +// REQUIRES: can-test-hardening-assertions-fast
    +// UNSUPPORTED: c++03, c++11, c++14
    +// UNSUPPORTED: libcpp-assertion-semantic={{ignore|observe}}
    +
    +// <set>
    +
    +// Call erase(const_iterator) and extract(const_iterator) with end().
    +
    +#include <set>
    +
    +#include "check_assertion.h"
    +
    +int main(int, char**) {
    +  {
    +    int a[] = {1, 2, 3};
    +    std::set<int> c(a, a + 3);
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.end()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.erase(c.cend()), "associative container::erase(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.cend()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    std::set<int> c;
    +    TEST_LIBCPP_ASSERT_FAILURE(
    +        c.extract(c.end()), "associative container::extract(iterator) called with a non-dereferenceable iterator");
    +  }
    +
    +  {
    +    int a[] = {1, 2, 3};
    +    std::multiset<int> c(a, a + 3);

    The multiset and multimap tests now have their own files under associative/multiset and associative/multimap, in https://github.com/llvm/llvm-project/commit/b4432791c29ef4cec27b6db4f8e860cfad5d807f. The map test had the same mix, so I split it the same way. The blocks are moved unchanged.

    ilyas-mallah ilyas-mallah commented on Nov 05, 2026 08:10 UTC
    Author

    @ldionne Everything is green on https://github.com/llvm/llvm-project/commit/65ae7c1fae840eb484a705b21a6d2aed15672f77 except the macOS generic-cxx03 job. It failed while setting up, when GitHub answered 429 three times to the checkout download. Could you rerun it? The test split you asked for is in.

    ilyas-mallah ilyas-mallah commented on Nov 22, 2026 21:08 UTC
    Author

    @ldionne GitHub still shows your changes-requested review on this PR, though the test split you asked for is pushed. Could you re-review or dismiss it? I don't have commit access, so someone would need to merge it after that.

    ilyas-mallah ilyas-mallah commented on Nov 26, 2026 19:40 UTC
    Author

    Thanks for starting the benchmarks on 10-21. The report job failed and posted nothing, so I read the run's artifacts. Only the macOS hardenedfast run compiles the new check in.

    On map, set, multimap and multiset, the 16 erase(iterator) rows are between -4.8% and +5.1%, median +0.15%. One is marked significant, multiset<int>/32 at +1.1%. The 16 range erase rows are between -2.6% and +2.5%. Six of those are significant, and four of the six are faster. No erase(key) row with an existing key is significant. There's no extract benchmark.

    I've also merged main to resolve the conflict with #245965.

    Reviewers
    Assignees
    ilyas-mallah ilyas-mallah
    Labels
    risk: low confidence: 89.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63% (MEDIUM) · Higher = larger blast radius
    63%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 89.6% · Lower = rushed or shallow review
    89.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 6.5% · Safe to merge
    6.5%