summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-08-09 23:20:49 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2022-08-10 00:22:08 -0700
commit7523bcf5dc9d8026006777c14e15c44430837f51 (patch)
tree23f0bca4b5123a68a4a8bc14c1c1e8103e0731f3 /lib
parent5b9755278927555b18880c138525557b5ee75bd0 (diff)
downloadgnulib-7523bcf5dc9d8026006777c14e15c44430837f51.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/intprops.h14
1 files changed, 7 insertions, 7 deletions
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_<op>_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_<op>_WRAPV, INT_<op>_OK, and
- INT_<op>_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_<op>_WRAPV, INT_<op>_OK, and INT_<op>_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))