From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 034E73857809; Thu, 27 May 2021 17:37:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 034E73857809 Received: by mail-ed1-x52f.google.com with SMTP id o5so1794201edc.5; Thu, 27 May 2021 10:37:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language; bh=gnYWrJHbPPlVyKUrF5lTndg96SeLJbCvCGK9bgxXQHs=; b=H2l1H8kvMRr0v5hCNotyWN8T3Mcqs151Vk7ExXmtbLa5G3HGI1oUipU+JlGD98+9dn qfOJZ8DmxzC77m0hZqjF4s1ae0e13KVCJI4Tt7QaqMM/7c2XEEHpA8gVblkSPAYGTzL2 EY1BBKVrtzd7RlrmHmHz49cFuvSCI9vLxEDnuFENik5Z+lA244XALfo/IdhmvXmoVTXb htOes7vAfD/WUdYKx0lRfHHH9dWja3wELqiLUopLjKvzFhwX1ceRlPxqVKFL48fz+MBe 3HT/uOugFIxqWcueQ0EvpIoGwE6BV/fF4d+hNi9jR74MMePdQTpSf92eKF+2gJcuft96 eEIA== X-Gm-Message-State: AOAM53045uDrjbYm8eFmLIw6/Jd1DeXgjtnHmhZn5sTA+El9GhuyoOsH 2w7yYpibnBnoD7rWDTmZ140ZyzY6mbo= X-Google-Smtp-Source: ABdhPJzyrlgqgDtblsKezTDuzWGFNe5gEOE+/Kf6jyTKA4RFSYIKh3TEQbN1z77VAo4jnW39SBuzzA== X-Received: by 2002:a50:ab16:: with SMTP id s22mr5327021edc.323.1622137027637; Thu, 27 May 2021 10:37:07 -0700 (PDT) Received: from [10.34.4.133] ([109.190.253.11]) by smtp.googlemail.com with ESMTPSA id g1sm1290139ejf.29.2021.05.27.10.37.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 10:37:06 -0700 (PDT) From: =?UTF-8?Q?Fran=c3=a7ois_Dumont?= Subject: [PATCH] Use _GLIBCXX_ASSERTIONS as _GLIBCXX_DEBUG light To: "libstdc++@gcc.gnu.org" Cc: gcc-patches Message-ID: <6ccc9e9e-af8b-fd06-4ad3-4bc021aa364e@gmail.com> Date: Thu, 27 May 2021 19:37:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------FCD9E88B7BA769C29370674B" Content-Language: fr X-Spam-Status: No, score=-9.7 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, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2021 17:37:11 -0000 This is a multi-part message in MIME format. --------------FCD9E88B7BA769C29370674B Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit We have been talking for a long time of a debug mode with less impact on performances. I propose to simply use the existing _GLIBCXX_ASSERTIONS macro.     libstdc++: [_GLIBCXX_ASSERTIONS] Activate basic debug checks     Use _GLIBCXX_ASSERTIONS as a _GLIBCXX_DEBUG light mode. When defined it activates     all _GLIBCXX_DEBUG checks but skipping those requiring to loop through the iterator     range unless in case of constexpr.     libstdc++-v3/ChangeLog:             * include/debug/debug.h [_GLIBCXX_ASSERTIONS]: Define debug macros non-empty.             * include/debug/helper_functions.h: Cleanup comment about removed _Iter_base.             * include/debug/functions.h (__skip_debug_runtime_check): New, returns false if             _GLIBCXX_DEBUG is defined or if constant evaluated.             (__check_sorted, __check_partitioned_lower, __check_partitioned_upper): Use latter. Tested under Linux x64. Ok to commit ? François --------------FCD9E88B7BA769C29370674B Content-Type: text/x-patch; charset=UTF-8; name="assertion_mode.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="assertion_mode.patch" diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h index 116f2f023e2..2e6ce1c8a93 100644 --- a/libstdc++-v3/include/debug/debug.h +++ b/libstdc++-v3/include/debug/debug.h @@ -61,7 +61,7 @@ namespace __gnu_debug struct _Safe_iterator; } -#ifndef _GLIBCXX_DEBUG +#ifndef _GLIBCXX_ASSERTIONS # define __glibcxx_requires_cond(_Cond,_Msg) # define __glibcxx_requires_valid_range(_First,_Last) diff --git a/libstdc++-v3/include/debug/functions.h b/libstdc++-v3/include/debug/functions.h index 6cac11f2abd..ee0eb877568 100644 --- a/libstdc++-v3/include/debug/functions.h +++ b/libstdc++-v3/include/debug/functions.h @@ -48,6 +48,25 @@ namespace __gnu_debug template struct _Is_contiguous_sequence : std::__false_type { }; + _GLIBCXX20_CONSTEXPR + inline bool + __skip_debug_runtime_check() + { + // We could be here while only _GLIBCXX_ASSERTIONS has been defined. + // In this case we skip expensive runtime checks, constexpr will still + // be checked. + return +#ifndef _GLIBCXX_DEBUG +# if _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED + !__builtin_is_constant_evaluated(); +# else + true; +# endif +#else + false; +#endif + } + /* Checks that [first, last) is a valid range, and then returns * __first. This routine is useful when we can't use a separate * assertion statement because, e.g., we are in a constructor. @@ -260,8 +279,9 @@ namespace __gnu_debug inline bool __check_sorted(const _InputIterator& __first, const _InputIterator& __last) { - return __check_sorted_aux(__first, __last, - std::__iterator_category(__first)); + return __skip_debug_runtime_check() + || __check_sorted_aux(__first, __last, + std::__iterator_category(__first)); } template @@ -270,8 +290,9 @@ namespace __gnu_debug __check_sorted(const _InputIterator& __first, const _InputIterator& __last, _Predicate __pred) { - return __check_sorted_aux(__first, __last, __pred, - std::__iterator_category(__first)); + return __skip_debug_runtime_check() + || __check_sorted_aux(__first, __last, __pred, + std::__iterator_category(__first)); } template @@ -351,6 +372,9 @@ namespace __gnu_debug __check_partitioned_lower(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { + if (__skip_debug_runtime_check()) + return true; + while (__first != __last && *__first < __value) ++__first; if (__first != __last) @@ -368,6 +392,9 @@ namespace __gnu_debug __check_partitioned_upper(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { + if (__skip_debug_runtime_check()) + return true; + while (__first != __last && !(__value < *__first)) ++__first; if (__first != __last) @@ -387,6 +414,9 @@ namespace __gnu_debug _ForwardIterator __last, const _Tp& __value, _Pred __pred) { + if (__skip_debug_runtime_check()) + return true; + while (__first != __last && bool(__pred(*__first, __value))) ++__first; if (__first != __last) @@ -405,6 +435,9 @@ namespace __gnu_debug _ForwardIterator __last, const _Tp& __value, _Pred __pred) { + if (__skip_debug_runtime_check()) + return true; + while (__first != __last && !bool(__pred(__value, *__first))) ++__first; if (__first != __last) diff --git a/libstdc++-v3/include/debug/helper_functions.h b/libstdc++-v3/include/debug/helper_functions.h index c0144ced979..587eba2f3e5 100644 --- a/libstdc++-v3/include/debug/helper_functions.h +++ b/libstdc++-v3/include/debug/helper_functions.h @@ -30,8 +30,8 @@ #define _GLIBCXX_DEBUG_HELPER_FUNCTIONS_H 1 #include // for __addressof -#include // for iterator_traits, - // categories and _Iter_base +#include // for iterator_traits and + // categories #include // for __is_integer #include // for pair --------------FCD9E88B7BA769C29370674B--