From 7523bcf5dc9d8026006777c14e15c44430837f51 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 9 Aug 2022 23:20:49 -0700 Subject: [PATCH 2/6] intprops: refactor _GL_HAS_BUILTIN_OVERFLOW_P MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P) [_GL_HAS_BUILTIN_OVERFLOW_P]: Use __builtin_sub_overflow_p directly rather than indirectly via INT_SUBTRACT_OVERFLOW. This simplifies future changes, and doesn’t change the generated code. --- ChangeLog | 6 ++++++ lib/intprops.h | 14 +++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcf5ae8266..18e0f7f4f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2022-08-09 Paul Eggert + intprops: refactor _GL_HAS_BUILTIN_OVERFLOW_P + * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P) + [_GL_HAS_BUILTIN_OVERFLOW_P]: Use __builtin_sub_overflow_p + directly rather than indirectly via INT_SUBTRACT_OVERFLOW. + This simplifies future changes, and doesn’t change the generated code. + verify: port ‘assume’ to C23 non-GCC * lib/verify.h (assume): Use C23's unreachable if available and if GCC and/or MSC primitives are not available. diff --git a/lib/intprops.h b/lib/intprops.h index d4a917f72a..40c60fc4a8 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -129,12 +129,11 @@ /* Range overflow checks. The INT__RANGE_OVERFLOW macros return 1 if the corresponding C - operators might not yield numerically correct answers due to - arithmetic overflow. They do not rely on undefined or - implementation-defined behavior. Their implementations are simple - and straightforward, but they are harder to use and may be less - efficient than the INT__WRAPV, INT__OK, and - INT__OVERFLOW macros described below. + operators overflow arithmetically when given the same arguments. + These macros do not rely on undefined or implementation-defined behavior. + Although their implementations are simple and straightforward, + they are harder to use and may be less efficient than the + INT__WRAPV, INT__OK, and INT__OVERFLOW macros described below. Example usage: @@ -365,7 +364,8 @@ #define INT_SUBTRACT_OVERFLOW(a, b) \ _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW) #if _GL_HAS_BUILTIN_OVERFLOW_P -# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a) +# define INT_NEGATE_OVERFLOW(a) \ + __builtin_sub_overflow_p (0, a, (__typeof__ (- (a))) 0) #else # define INT_NEGATE_OVERFLOW(a) \ INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a)) -- 2.34.1