From patchwork Thu May 27 17:37:03 2021 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: 1484750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@gcc.gnu.org; receiver=) Authentication-Results: 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=r3OgVHDZ; dkim-atps=neutral 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 ozlabs.org (Postfix) with ESMTPS id 4FrZl06kGqz9sTD for ; Fri, 28 May 2021 03:37:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79570395B462; Thu, 27 May 2021 17:37:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79570395B462 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1622137032; bh=gnYWrJHbPPlVyKUrF5lTndg96SeLJbCvCGK9bgxXQHs=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=r3OgVHDZfz0WrH5CttgdB8JFGYcdC+0h50uR1UeaWLuFummGYYp249VpRq8MwhDk+ HkJLIuCM0k6kIigHc/QE5JcRNwPFrfFLTTKRb9evRDrgj+NuhmQvpshYIVxtVXZgmG JC97V+CdF0w0Cdh4uB8N225hSVMshqXZTbYrkQVE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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) Subject: [PATCH] Use _GLIBCXX_ASSERTIONS as _GLIBCXX_DEBUG light To: "libstdc++@gcc.gnu.org" 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-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: 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?= Cc: gcc-patches Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" 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 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