From patchwork Mon Jan 23 06:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 47044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1448894wrn; Sun, 22 Jan 2023 22:03:44 -0800 (PST) X-Google-Smtp-Source: AMrXdXtKU4UiFrz1MH6sB2x4Cg0HcQeIj3VC9f+7p1qDA9GqMS13nM1XhumeMOAM7PsOj31Z4T4B X-Received: by 2002:a05:6402:194c:b0:498:b9ea:1896 with SMTP id f12-20020a056402194c00b00498b9ea1896mr28356690edz.9.1674453824413; Sun, 22 Jan 2023 22:03:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674453824; cv=none; d=google.com; s=arc-20160816; b=DP7QYnnDnvpS6kqd/54YIObN2Xm3JkH1MewBU0IEYqDwPOkPH2FMsw3qTEukI7rKX+ Yc/uSwFvBaN3zhU7mUhw89tmSlQupFZuHPBV+9qUdZZyb6NV1RMSy0vB7wVphApDTIQY ottTH26CsR1PPFOezmFoorsIhW+EpEEk1sVhRr9PlJR0aPVOwZI1Qd36OMkt6LiVGGST Eijz52K8UqxFlf0gN33ORfIZmpuYP4SzLq4bMOwsshvJ4jqR/doPlk8JgBFKdwevJ3gO WCn/HJRL0oSDROb3ZlTngXXX8RCoOBus03bpiHwDn4nnPwozzNkmYFNe+03ZU8kEWC60 cpXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:cc:to :content-language:user-agent:mime-version:date:message-id :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=ZL0ZYG8uZ8oZp0xvD+lYbj9wBcWrepyYC7GLRCCiFkY=; b=llUNdGpyTfBLMtiOqPPCAMu/SiRB1ntHn+YMU6Xl7i+tsVSCJum+JA86gOc4f2R8AC JcrGH+sDgEUMDmYPdmwE4lC+dnjJTIo3Z8unh5DwbubIE8f4mhixRKGwEDXGTsyDzpKz hWT2AfNjFufMloLL/q4t3jRtG0qMDdK8RjLS7UG5QCB8IjYMWOQLHHWrtWxkH/krv4x+ NW6QieotPgt3dodlvRcW1FF9qQT9vrl1EiXfOinb38YuBt0JgvNdEeYCSjZu/F/qxaiW l7CBRuZNMjkgxyC1lIJyQcpaRIxRMZAnhiA2ab3XDMWVf48uIgkr511ukXua9leXwL05 VPxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cuoAoYqa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d17-20020aa7d691000000b00498c4fa0ce7si20760741edr.164.2023.01.22.22.03.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Jan 2023 22:03:44 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=cuoAoYqa; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DF41385B501 for ; Mon, 23 Jan 2023 06:03:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DF41385B501 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674453798; bh=ZL0ZYG8uZ8oZp0xvD+lYbj9wBcWrepyYC7GLRCCiFkY=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=cuoAoYqamxXheSsenh8EPl1dCxOWp7UOuAmvemKfiUdxwTxgeah3SbgmbO71XtNH/ 3pATaF1KfeyHGtmOiiTP1YbUhNUbTWlSta0R7q/C9ZjVF0jVHVnZXNGZxyZJXg0voD w0UQ+aAjt8EU1hYt/LEmX3wO3RFFbt9jsazFeDQI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 260763858D38; Mon, 23 Jan 2023 06:02:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 260763858D38 Received: by mail-ej1-x631.google.com with SMTP id rl14so24359881ejb.2; Sun, 22 Jan 2023 22:02:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZL0ZYG8uZ8oZp0xvD+lYbj9wBcWrepyYC7GLRCCiFkY=; b=NrS2Zy38Bk1EUEjkwDvC2YuqWDT+ZxYaqik21k4QO1y3JUCDt0wajr5HTTBFLC6pWs GLL65MaaMeVpHm9iso4LdpfXm+JVZT54iQ9N7S+9Xfkuw3xTaKoKRnNA9NiTGtLM88eP 6EcC9HBBY/W3ec5YuYLNIDZHjqhLSaJAfJLnI150BDhrDO4sy+5JlaGA59RqtoVsohOD RhdP8FMa+Y7hqgItlWVcIsRrscpItnD0j+hFLtxJeqkFR6BH68Bw/j6XNjT27MqugC30 HYdjCpQPFz8QCVYd45KTjG0aLC21P7sSdszZb+sl25LH/cxKCEQeIkh9mVFJVx1psMVf Kmzw== X-Gm-Message-State: AFqh2krSvSY69DAGMCtT9juLsAZUxUXCCK4mwlNNG4XpEr9eC6daQbqQ Qc7t7WYe2TjCBmQdSMhAtJAbbMp33Lg= X-Received: by 2002:a17:906:e247:b0:84d:3928:66b6 with SMTP id gq7-20020a170906e24700b0084d392866b6mr23961874ejb.40.1674453750482; Sun, 22 Jan 2023 22:02:30 -0800 (PST) Received: from [10.10.0.56] ([109.190.253.14]) by smtp.googlemail.com with ESMTPSA id 14-20020a170906308e00b0084d3acda5fasm20089892ejv.189.2023.01.22.22.02.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 22 Jan 2023 22:02:29 -0800 (PST) Message-ID: Date: Mon, 23 Jan 2023 07:02:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Content-Language: fr To: "libstdc++@gcc.gnu.org" Cc: gcc-patches Subject: [PATCH][_GLIBCXX_DEBUG] Remove useless checks X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: =?utf-8?q?Fran=C3=A7ois_Dumont_via_Gcc-patches?= From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Reply-To: =?utf-8?q?Fran=C3=A7ois_Dumont?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755792093103662751?= X-GMAIL-MSGID: =?utf-8?q?1755792093103662751?= libstdc++: [_GLIBCXX_DEBUG] Remove useless constructor checks     Creating a safe iterator from a normal iterator is done within the library where we     already know that it is done correctly. The rare situation where a user would use safe     iterators for his own purpose is non-Standard code so outside _GLIBCXX_DEBUG scope. For     those reasons the __msg_init_singular is useless and can be removed.     Additionally in the copy constructor used for post-increment and post-decrement operators     the __msg_init_copy_singular check can also be ommitted because of the preliminary     __msg_bad_inc and __msg_bad_dec checks.     libstdc++-v3/ChangeLog:             * include/debug/safe_iterator.h (_Safe_iterator<>::_Unsafe_call): New.             (_Safe_iterator(const _Safe_iterator&, _Unsafe_call): New.             (_Safe_iterator::operator++(int)): Use latter.             (_Safe_iterator::operator--(int)): Likewise.             (_Safe_iterator(_Iterator, const _Safe_sequence_base*)): Remove !_M_insular()             check.             * include/debug/safe_local_iterator.h (_Safe_local_iterator<>::_Unsafe_call):             New.             (_Safe_local_iterator(const _Safe_local_iterator&, _Unsafe_call): New.             (_Safe_local_iterator::operator++(int)): Use latter.             * src/c++11/debug.cc (_S_debug_messages): Add as comment the _Debug_msg_id             entry associated to the array entry. Tested under Linux x64. Ok to commit ? François diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index f364477a00c..570c826649f 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -129,6 +129,12 @@ namespace __gnu_debug typename _Sequence::_Base::iterator, typename _Sequence::_Base::const_iterator>::__type _OtherIterator; + struct _Unsafe_call { }; + + _Safe_iterator(const _Safe_iterator& __x, _Unsafe_call) _GLIBCXX_NOEXCEPT + : _Iter_base(__x.base()), _Safe_base() + { _M_attach(__x._M_sequence); } + public: typedef _Iterator iterator_type; typedef typename _Traits::iterator_category iterator_category; @@ -154,11 +160,7 @@ namespace __gnu_debug _Safe_iterator(_Iterator __i, const _Safe_sequence_base* __seq) _GLIBCXX_NOEXCEPT : _Iter_base(__i), _Safe_base(__seq, _S_constant()) - { - _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(), - _M_message(__msg_init_singular) - ._M_iterator(*this, "this")); - } + { } /** * @brief Copy construction. @@ -339,7 +341,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(), _M_message(__msg_bad_inc) ._M_iterator(*this, "this")); - _Safe_iterator __ret = *this; + _Safe_iterator __ret(*this, _Unsafe_call()); ++*this; return __ret; } @@ -514,6 +516,13 @@ namespace __gnu_debug protected: typedef typename _Safe_base::_OtherIterator _OtherIterator; + typedef typename _Safe_base::_Unsafe_call _Unsafe_call; + + _Safe_iterator(const _Safe_iterator& __x, + _Unsafe_call __unsafe_call) _GLIBCXX_NOEXCEPT + : _Safe_base(__x, __unsafe_call) + { } + public: /// @post the iterator is singular and unattached _Safe_iterator() _GLIBCXX_NOEXCEPT { } @@ -596,7 +605,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(), _M_message(__msg_bad_inc) ._M_iterator(*this, "this")); - _Safe_iterator __ret = *this; + _Safe_iterator __ret(*this, _Unsafe_call()); ++*this; return __ret; } @@ -627,7 +636,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_decrementable(), _M_message(__msg_bad_dec) ._M_iterator(*this, "this")); - _Safe_iterator __ret = *this; + _Safe_iterator __ret(*this, _Unsafe_call()); --*this; return __ret; } @@ -653,6 +662,12 @@ namespace __gnu_debug typedef _Safe_iterator<_OtherIterator, _Sequence, std::random_access_iterator_tag> _OtherSelf; + typedef typename _Safe_base::_Unsafe_call _Unsafe_call; + _Safe_iterator(const _Safe_iterator& __x, + _Unsafe_call __unsafe_call) _GLIBCXX_NOEXCEPT + : _Safe_base(__x, __unsafe_call) + { } + public: typedef typename _Safe_base::difference_type difference_type; typedef typename _Safe_base::reference reference; @@ -744,7 +759,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(), _M_message(__msg_bad_inc) ._M_iterator(*this, "this")); - _Safe_iterator __ret = *this; + _Safe_iterator __ret(*this, _Unsafe_call()); ++*this; return __ret; } @@ -771,7 +786,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_decrementable(), _M_message(__msg_bad_dec) ._M_iterator(*this, "this")); - _Safe_iterator __ret = *this; + _Safe_iterator __ret(*this, _Unsafe_call()); --*this; return __ret; } diff --git a/libstdc++-v3/include/debug/safe_local_iterator.h b/libstdc++-v3/include/debug/safe_local_iterator.h index 624f0ddad0f..feb54d082d4 100644 --- a/libstdc++-v3/include/debug/safe_local_iterator.h +++ b/libstdc++-v3/include/debug/safe_local_iterator.h @@ -84,6 +84,13 @@ namespace __gnu_debug typedef _Safe_local_iterator _Self; typedef _Safe_local_iterator<_OtherIterator, _Sequence> _OtherSelf; + struct _Unsafe_call { }; + + _Safe_local_iterator(const _Safe_local_iterator& __x, + _Unsafe_call) noexcept + : _Iter_base(__x.base()) + { _M_attach(__x._M_sequence); } + public: typedef _Iterator iterator_type; typedef typename _Traits::iterator_category iterator_category; @@ -104,11 +111,7 @@ namespace __gnu_debug */ _Safe_local_iterator(_Iterator __i, const _Safe_sequence_base* __cont) : _Iter_base(__i), _Safe_base(__cont, _S_constant()) - { - _GLIBCXX_DEBUG_VERIFY(!this->_M_singular(), - _M_message(__msg_init_singular) - ._M_iterator(*this, "this")); - } + { } /** * @brief Copy construction. @@ -282,7 +285,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY(this->_M_incrementable(), _M_message(__msg_bad_inc) ._M_iterator(*this, "this")); - _Safe_local_iterator __ret = *this; + _Safe_local_iterator __ret(*this, _Unsafe_call{}); ++*this; return __ret; } diff --git a/libstdc++-v3/src/c++11/debug.cc b/libstdc++-v3/src/c++11/debug.cc index d4ee5fa12dc..926e8be6122 100644 --- a/libstdc++-v3/src/c++11/debug.cc +++ b/libstdc++-v3/src/c++11/debug.cc @@ -181,86 +181,139 @@ namespace __gnu_debug const char* const _S_debug_messages[] = { // General Checks + // __msg_valid_range "function requires a valid iterator range [%1.name;, %2.name;)", + // __msg_insert_singular "attempt to insert into container with a singular iterator", + // __msg_insert_different "attempt to insert into container with an iterator" " from a different container", + // __msg_erase_bad "attempt to erase from container with a %2.state; iterator", + // __msg_erase_different "attempt to erase from container with an iterator" " from a different container", + // __msg_subscript_oob "attempt to subscript container with out-of-bounds index %2;," " but container only holds %3; elements", + // __msg_empty "attempt to access an element in an empty container", + // __msg_unpartitioned "elements in iterator range [%1.name;, %2.name;)" " are not partitioned by the value %3;", + // __msg_unpartitioned_pred "elements in iterator range [%1.name;, %2.name;)" " are not partitioned by the predicate %3; and value %4;", + // __msg_unsorted "elements in iterator range [%1.name;, %2.name;) are not sorted", + // __msg_unsorted_pred "elements in iterator range [%1.name;, %2.name;)" " are not sorted according to the predicate %3;", + // __msg_not_heap "elements in iterator range [%1.name;, %2.name;) do not form a heap", + // __msg_not_heap_pred "elements in iterator range [%1.name;, %2.name;)" " do not form a heap with respect to the predicate %3;", // std::bitset checks + // __msg_bad_bitset_write "attempt to write through a singular bitset reference", + // __msg_bad_bitset_read "attempt to read from a singular bitset reference", + // __msg_bad_bitset_flip "attempt to flip a singular bitset reference", // std::list checks + // __msg_self_splice "attempt to splice a list into itself", + // __msg_splice_alloc "attempt to splice lists with unequal allocators", + // __msg_splice_bad "attempt to splice elements referenced by a %1.state; iterator", + // __msg_splice_other "attempt to splice an iterator from a different container", + // __msg_splice_overlap "splice destination %1.name;" " occurs within source range [%2.name;, %3.name;)", // iterator checks + // __msg_init_singular "attempt to initialize an iterator that will immediately become singular", + // __msg_init_copy_singular "attempt to copy-construct an iterator from a singular iterator", + // __msg_init_const_singular "attempt to construct a constant iterator" " from a singular mutable iterator", + // __msg_copy_singular "attempt to copy from a singular iterator", + // __msg_bad_deref "attempt to dereference a %1.state; iterator", + // __msg_bad_inc "attempt to increment a %1.state; iterator", + // __msg_bad_dec "attempt to decrement a %1.state; iterator", + // __msg_iter_subscript_oob "attempt to subscript a %1.state; iterator %2; step from" " its current position, which falls outside its dereferenceable range", + // __msg_advance_oob "attempt to advance a %1.state; iterator %2; steps," " which falls outside its valid range", + // __msg_retreat_oob "attempt to retreat a %1.state; iterator %2; steps," " which falls outside its valid range", + // __msg_iter_compare_bad "attempt to compare a %1.state; iterator to a %2.state; iterator", + // __msg_compare_different "attempt to compare iterators from different sequences", + // __msg_iter_order_bad "attempt to order a %1.state; iterator to a %2.state; iterator", + // __msg_order_different "attempt to order iterators from different sequences", + // __msg_distance_bad "attempt to compute the difference between a %1.state;" " iterator to a %2.state; iterator", + // __msg_distance_different "attempt to compute the different between two iterators" " from different sequences", // istream_iterator + // __msg_deref_istream "attempt to dereference an end-of-stream istream_iterator", + // __msg_inc_istream "attempt to increment an end-of-stream istream_iterator", // ostream_iterator + // __msg_output_ostream "attempt to output via an ostream_iterator with no associated stream", // istreambuf_iterator + // __msg_deref_istreambuf "attempt to dereference an end-of-stream istreambuf_iterator" " (this is a GNU extension)", + // __msg_inc_istreambuf "attempt to increment an end-of-stream istreambuf_iterator", // std::forward_list + // __msg_insert_after_end "attempt to insert into container after an end iterator", + // __msg_erase_after_bad "attempt to erase from container after a %2.state; iterator not followed" " by a dereferenceable one", + // __msg_valid_range2 "function requires a valid iterator range (%2.name;, %3.name;)" ", \"%2.name;\" shall be before and not equal to \"%3.name;\"", // std::unordered_container::local_iterator + // __msg_local_iter_compare_bad "attempt to compare local iterators from different unordered container" " buckets", + // __msg_non_empty_range "function requires a non-empty iterator range [%1.name;, %2.name;)", + // __msg_self_move_assign "attempt to self move assign", + // __msg_bucket_index_oob "attempt to access container with out-of-bounds bucket index %2;," " container only holds %3; buckets", + // __msg_valid_load_factor "load factor shall be positive", + // __msg_equal_allocs "allocators must be equal", + // __msg_insert_range_from_self "attempt to insert with an iterator range [%1.name;, %2.name;) from this" " container", + // __msg_irreflexive_ordering "comparison doesn't meet irreflexive requirements, assert(!(a < a))" };