From patchwork Fri Oct 8 11:21:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1538299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=TSWynKD/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HQm6T5BnFz9sP7 for ; Fri, 8 Oct 2021 22:24:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 759C63857802 for ; Fri, 8 Oct 2021 11:23:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 759C63857802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633692239; bh=xY++99zqU3nVcgJkdTjp1EXNogBcqb39HOL6fmPC1CQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=TSWynKD/EDdgw9mTh3GWQPajgAXm35olQwi1fokB23MF9WlC/oBamGczAPyKYqX1e 8iFbjZVXC72RfI7R0tSsh77Ta+CsdJCQ+oE1hdIaOEc9GTWMQZOAD5d/mZ/5MeKIe9 IxzIqXf4owHfyVmQP0JVbfb2yahIRrPCGGIDkmVY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id CB2E03857800 for ; Fri, 8 Oct 2021 11:21:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CB2E03857800 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-512-0-czb_LTMF29sJruRgPWCA-1; Fri, 08 Oct 2021 07:21:18 -0400 X-MC-Unique: 0-czb_LTMF29sJruRgPWCA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A0C01006AC5; Fri, 8 Oct 2021 11:21:17 +0000 (UTC) Received: from localhost (unknown [10.33.37.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1BB9ADC0; Fri, 8 Oct 2021 11:21:16 +0000 (UTC) Date: Fri, 8 Oct 2021 12:21:15 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Restore debug checks in uniform container erasure functions Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Cc: =?iso-8859-1?q?Fran=E7ois?= Dumont Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This partially reverts commit 561078480ffb5adb68577276c6b23e4ee7b39272. If we avoid all debug mode checks when erasing elements then we fail to invalidate safe iterators to the removed elements. This reverts the recent changes in r12-4083 and r12-4233, restoring the debug checking. libstdc++-v3/ChangeLog: * include/experimental/deque (erase, erase_if): Revert changes to avoid debug mode overhead. * include/experimental/map (erase, erase_if): Likewise. * include/experimental/set (erase, erase_if): Likewise. * include/experimental/unordered_map (erase, erase_if): Likewise. * include/experimental/unordered_set (erase, erase_if): Likewise. * include/experimental/vector (erase, erase_if): Likewise. * include/std/deque (erase, erase_if): Likewise. * include/std/map (erase, erase_if): Likewise. * include/std/set (erase, erase_if): Likewise. * include/std/unordered_map (erase, erase_if): Likewise. * include/std/unordered_set (erase, erase_if): Likewise. * include/std/vector (erase, erase_if): Likewise. Tested powerpc64le-linux. Committed to trunk. commit 82e3a826871effc7093852a9181f641c693ae94f Author: Jonathan Wakely Date: Thu Oct 7 20:33:45 2021 libstdc++: Restore debug checks in uniform container erasure functions This partially reverts commit 561078480ffb5adb68577276c6b23e4ee7b39272. If we avoid all debug mode checks when erasing elements then we fail to invalidate safe iterators to the removed elements. This reverts the recent changes in r12-4083 and r12-4233, restoring the debug checking. libstdc++-v3/ChangeLog: * include/experimental/deque (erase, erase_if): Revert changes to avoid debug mode overhead. * include/experimental/map (erase, erase_if): Likewise. * include/experimental/set (erase, erase_if): Likewise. * include/experimental/unordered_map (erase, erase_if): Likewise. * include/experimental/unordered_set (erase, erase_if): Likewise. * include/experimental/vector (erase, erase_if): Likewise. * include/std/deque (erase, erase_if): Likewise. * include/std/map (erase, erase_if): Likewise. * include/std/set (erase, erase_if): Likewise. * include/std/unordered_map (erase, erase_if): Likewise. * include/std/unordered_set (erase, erase_if): Likewise. * include/std/vector (erase, erase_if): Likewise. diff --git a/libstdc++-v3/include/experimental/deque b/libstdc++-v3/include/experimental/deque index 710833ebcad..a76fb659bbf 100644 --- a/libstdc++-v3/include/experimental/deque +++ b/libstdc++-v3/include/experimental/deque @@ -50,16 +50,16 @@ inline namespace fundamentals_v2 inline void erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred) { - _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont; - __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end()); + __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), + __cont.end()); } template inline void erase(deque<_Tp, _Alloc>& __cont, const _Up& __value) { - _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont; - __c.erase(std::remove(__c.begin(), __c.end(), __value), __c.end()); + __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), + __cont.end()); } namespace pmr { diff --git a/libstdc++-v3/include/experimental/map b/libstdc++-v3/include/experimental/map index ef69fadf944..0c0f42222f5 100644 --- a/libstdc++-v3/include/experimental/map +++ b/libstdc++-v3/include/experimental/map @@ -50,19 +50,13 @@ inline namespace fundamentals_v2 typename _Predicate> inline void erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Alloc>& __c = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Alloc>& __c = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template> diff --git a/libstdc++-v3/include/experimental/set b/libstdc++-v3/include/experimental/set index 7a5986aec0e..c3f5433e995 100644 --- a/libstdc++-v3/include/experimental/set +++ b/libstdc++-v3/include/experimental/set @@ -50,19 +50,13 @@ inline namespace fundamentals_v2 typename _Predicate> inline void erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::set<_Key, _Compare, _Alloc>& __c = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::multiset<_Key, _Compare, _Alloc>& __c = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template> diff --git a/libstdc++-v3/include/experimental/unordered_map b/libstdc++-v3/include/experimental/unordered_map index eba989713fa..0b915ab13e5 100644 --- a/libstdc++-v3/include/experimental/unordered_map +++ b/libstdc++-v3/include/experimental/unordered_map @@ -51,22 +51,14 @@ inline namespace fundamentals_v2 inline void erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __c - = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __c - = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template, diff --git a/libstdc++-v3/include/experimental/unordered_set b/libstdc++-v3/include/experimental/unordered_set index bc5cc11419e..87db4464401 100644 --- a/libstdc++-v3/include/experimental/unordered_set +++ b/libstdc++-v3/include/experimental/unordered_set @@ -51,21 +51,14 @@ inline namespace fundamentals_v2 inline void erase_if(unordered_set<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_set<_Key, _Hash, _CPred, _Alloc>& __c = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __c - = __cont; - std::__detail::__erase_nodes_if(__c, __pred); - } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template, diff --git a/libstdc++-v3/include/experimental/vector b/libstdc++-v3/include/experimental/vector index c45a500ef5e..a14aedf3364 100644 --- a/libstdc++-v3/include/experimental/vector +++ b/libstdc++-v3/include/experimental/vector @@ -52,16 +52,16 @@ inline namespace fundamentals_v2 inline void erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred) { - _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont; - __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end()); + __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), + __cont.end()); } template inline void erase(vector<_Tp, _Alloc>& __cont, const _Up& __value) { - _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont; - __c.erase(std::remove(__c.begin(), __c.end(), __value), __c.end()); + __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), + __cont.end()); } namespace pmr { diff --git a/libstdc++-v3/include/std/deque b/libstdc++-v3/include/std/deque index 71993e757a5..473479c44ac 100644 --- a/libstdc++-v3/include/std/deque +++ b/libstdc++-v3/include/std/deque @@ -95,28 +95,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline typename deque<_Tp, _Alloc>::size_type erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred) { - _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont; using namespace __gnu_cxx; - const auto __osz = __c.size(); - const auto __end = __c.end(); - auto __removed = std::__remove_if(__c.begin(), __end, + const auto __osz = __cont.size(); + const auto __end = __cont.end(); + auto __removed = std::__remove_if(__cont.begin(), __end, __ops::__pred_iter(std::ref(__pred))); - __c.erase(__removed, __end); - return __osz - __c.size(); + __cont.erase(__removed, __end); + return __osz - __cont.size(); } template inline typename deque<_Tp, _Alloc>::size_type erase(deque<_Tp, _Alloc>& __cont, const _Up& __value) { - _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont; using namespace __gnu_cxx; - const auto __osz = __c.size(); - const auto __end = __c.end(); - auto __removed = std::__remove_if(__c.begin(), __end, + const auto __osz = __cont.size(); + const auto __end = __cont.end(); + auto __removed = std::__remove_if(__cont.begin(), __end, __ops::__iter_equals_val(__value)); - __c.erase(__removed, __end); - return __osz - __c.size(); + __cont.erase(__removed, __end); + return __osz - __cont.size(); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/map b/libstdc++-v3/include/std/map index 29265580995..44bd44b5922 100644 --- a/libstdc++-v3/include/std/map +++ b/libstdc++-v3/include/std/map @@ -95,19 +95,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename _Predicate> inline typename map<_Key, _Tp, _Compare, _Alloc>::size_type erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Alloc>& __c = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } template inline typename multimap<_Key, _Tp, _Compare, _Alloc>::size_type erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Alloc>& __c = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++20 diff --git a/libstdc++-v3/include/std/set b/libstdc++-v3/include/std/set index 24e6e633624..f1e1864937a 100644 --- a/libstdc++-v3/include/std/set +++ b/libstdc++-v3/include/std/set @@ -91,19 +91,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename _Predicate> inline typename set<_Key, _Compare, _Alloc>::size_type erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::set<_Key, _Compare, _Alloc>& __c = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } template inline typename multiset<_Key, _Compare, _Alloc>::size_type erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::multiset<_Key, _Compare, _Alloc>& __c = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++20 diff --git a/libstdc++-v3/include/std/unordered_map b/libstdc++-v3/include/std/unordered_map index 774c21fc28b..e6715069362 100644 --- a/libstdc++-v3/include/std/unordered_map +++ b/libstdc++-v3/include/std/unordered_map @@ -83,11 +83,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline typename unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>::size_type erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __c - = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } template @@ -95,11 +91,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION size_type erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __c - = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++20 diff --git a/libstdc++-v3/include/std/unordered_set b/libstdc++-v3/include/std/unordered_set index 3859eeaebd0..1ad93d0031b 100644 --- a/libstdc++-v3/include/std/unordered_set +++ b/libstdc++-v3/include/std/unordered_set @@ -83,21 +83,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline typename unordered_set<_Key, _Hash, _CPred, _Alloc>::size_type erase_if(unordered_set<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_set<_Key, _Hash, _CPred, _Alloc>& __c = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } template inline typename unordered_multiset<_Key, _Hash, _CPred, _Alloc>::size_type erase_if(unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { - _GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __c - = __cont; - return __detail::__erase_nodes_if(__c, __pred); - } + { return __detail::__erase_nodes_if(__cont, __pred); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++20 diff --git a/libstdc++-v3/include/std/vector b/libstdc++-v3/include/std/vector index 835fa8aeb69..096511c05b2 100644 --- a/libstdc++-v3/include/std/vector +++ b/libstdc++-v3/include/std/vector @@ -105,28 +105,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline typename vector<_Tp, _Alloc>::size_type erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred) { - _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont; using namespace __gnu_cxx; - const auto __osz = __c.size(); - const auto __end = __c.end(); - auto __removed(std::__remove_if(__c.begin(), __end, - __ops::__pred_iter(std::ref(__pred)))); - __c.erase(__removed, __end); - return __osz - __c.size(); + const auto __osz = __cont.size(); + const auto __end = __cont.end(); + auto __removed = std::__remove_if(__cont.begin(), __end, + __ops::__pred_iter(std::ref(__pred))); + __cont.erase(__removed, __end); + return __osz - __cont.size(); } template inline typename vector<_Tp, _Alloc>::size_type erase(vector<_Tp, _Alloc>& __cont, const _Up& __value) { - _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont; using namespace __gnu_cxx; - const auto __osz = __c.size(); - const auto __end = __c.end(); - auto __removed = std::__remove_if(__c.begin(), __end, + const auto __osz = __cont.size(); + const auto __end = __cont.end(); + auto __removed = std::__remove_if(__cont.begin(), __end, __ops::__iter_equals_val(__value)); - __c.erase(__removed, __end); - return __osz - __c.size(); + __cont.erase(__removed, __end); + return __osz - __cont.size(); } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std