From: "François Dumont" <frs.dumont@gmail.com>
To: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Use _GLIBCXX_ASSERTIONS as _GLIBCXX_DEBUG light
Date: Thu, 27 May 2021 19:37:03 +0200 [thread overview]
Message-ID: <6ccc9e9e-af8b-fd06-4ad3-4bc021aa364e@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1034 bytes --]
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
[-- Attachment #2: assertion_mode.patch --]
[-- Type: text/x-patch, Size: 4206 bytes --]
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<typename _Sequence>
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<typename _InputIterator, typename _Predicate>
@@ -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<typename _InputIterator>
@@ -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 <bits/move.h> // for __addressof
-#include <bits/stl_iterator_base_types.h> // for iterator_traits,
- // categories and _Iter_base
+#include <bits/stl_iterator_base_types.h> // for iterator_traits and
+ // categories
#include <bits/cpp_type_traits.h> // for __is_integer
#include <bits/stl_pair.h> // for pair
next reply other threads:[~2021-05-27 17:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-27 17:37 François Dumont [this message]
2021-05-31 17:17 ` François Dumont
2021-06-03 12:31 ` Jonathan Wakely
2021-06-07 4:25 ` François Dumont
2021-08-06 14:52 ` François Dumont
2021-08-08 19:34 ` François Dumont
2021-08-23 5:01 ` François Dumont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6ccc9e9e-af8b-fd06-4ad3-4bc021aa364e@gmail.com \
--to=frs.dumont@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).