update gnulib
This comes from gnulib 348402f2aac342bc925b7aaea9ee3cc353f427a9 plus a custom patch to support compilation of arpg in C++11. * lib/hard-locale.c, lib/hard-locale.h, m4/hard-locale.m4, m4/ltargz.m4: New files. * lib/Makefile.am, lib/alloca.in.h, lib/argmatch.c, lib/argmatch.h, lib/argp-ba.c, lib/argp-eexst.c, lib/argp-fmtstream.c, lib/argp-fmtstream.h, lib/argp-fs-xinl.c, lib/argp-help.c, lib/argp-namefrob.h, lib/argp-parse.c, lib/argp-pin.c, lib/argp-pv.c, lib/argp-pvh.c, lib/argp-xinl.c, lib/argp.h, lib/asnprintf.c, lib/basename-lgpl.c, lib/c-ctype.h, lib/c-strcase.h, lib/c-strcasecmp.c, lib/c-strcaseeq.h, lib/c-strncasecmp.c, lib/config.charset, lib/dirname-lgpl.c, lib/dirname.h, lib/dosname.h, lib/errno.in.h, lib/error.c, lib/error.h, lib/exitfail.c, lib/exitfail.h, lib/fcntl.in.h, lib/float+.h, lib/float.c, lib/float.in.h, lib/getopt.c, lib/getopt.in.h, lib/getopt1.c, lib/getopt_int.h, lib/gettext.h, lib/gettimeofday.c, lib/hard-locale.h, lib/intprops.h, lib/isatty.c, lib/itold.c, lib/localcharset.c, lib/localcharset.h, lib/lstat.c, lib/malloc.c, lib/mbrtowc.c, lib/mbsinit.c, lib/memchr.c, lib/mempcpy.c, lib/mkstemp.c, lib/mkstemps.c, lib/msvc-inval.c, lib/msvc-inval.h, lib/msvc-nothrow.c, lib/msvc-nothrow.h, lib/pathmax.h, lib/printf-args.c, lib/printf-args.h, lib/printf-parse.c, lib/printf-parse.h, lib/progname.c, lib/progname.h, lib/quote.h, lib/quotearg.c, lib/quotearg.h, lib/rawmemchr.c, lib/ref-add.sin, lib/ref-del.sin, lib/secure_getenv.c, lib/size_max.h, lib/sleep.c, lib/stat.c, lib/stdalign.in.h, lib/stdbool.in.h, lib/stddef.in.h, lib/stdint.in.h, lib/stdio.in.h, lib/stdlib.in.h, lib/stpcpy.c, lib/strcasecmp.c, lib/strchrnul.c, lib/streq.h, lib/strerror-override.c, lib/strerror-override.h, lib/strerror.c, lib/string.in.h, lib/strings.in.h, lib/stripslash.c, lib/strncasecmp.c, lib/strndup.c, lib/strnlen.c, lib/strverscmp.c, lib/sys_stat.in.h, lib/sys_time.in.h, lib/sys_types.in.h, lib/sys_wait.in.h, lib/sysexits.in.h, lib/tempname.c, lib/tempname.h, lib/time.in.h, lib/unistd.in.h, lib/vasnprintf.c, lib/vasnprintf.h, lib/verify.h, lib/vsnprintf.c, lib/wchar.in.h, lib/wctype.in.h, lib/xalloc-die.c, lib/xalloc-oversized.h, lib/xalloc.h, lib/xmalloc.c, lib/xsize.h, m4/00gnulib.m4, m4/absolute-header.m4, m4/alloca.m4, m4/argp.m4, m4/codeset.m4, m4/configmake.m4, m4/dirname.m4, m4/double-slash-root.m4, m4/errno_h.m4, m4/error.m4, m4/exponentd.m4, m4/extensions.m4, m4/extern-inline.m4, m4/fcntl-o.m4, m4/fcntl_h.m4, m4/float_h.m4, m4/getopt.m4, m4/gettimeofday.m4, m4/glibc21.m4, m4/gnulib-cache.m4, m4/gnulib-common.m4, m4/gnulib-comp.m4, m4/gnulib-tool.m4, m4/include_next.m4, m4/intmax_t.m4, m4/inttypes_h.m4, m4/isatty.m4, m4/largefile.m4, m4/localcharset.m4, m4/locale-fr.m4, m4/locale-ja.m4, m4/locale-zh.m4, m4/longlong.m4, m4/lstat.m4, m4/malloc.m4, m4/math_h.m4, m4/mbrtowc.m4, m4/mbsinit.m4, m4/mbstate_t.m4, m4/memchr.m4, m4/mempcpy.m4, m4/mkstemp.m4, m4/mkstemps.m4, m4/mmap-anon.m4, m4/msvc-inval.m4, m4/msvc-nothrow.m4, m4/multiarch.m4, m4/nocrash.m4, m4/off_t.m4, m4/pathmax.m4, m4/printf.m4, m4/quote.m4, m4/quotearg.m4, m4/rawmemchr.m4, m4/secure_getenv.m4, m4/size_max.m4, m4/sleep.m4, m4/ssize_t.m4, m4/stat.m4, m4/stdalign.m4, m4/stdbool.m4, m4/stddef_h.m4, m4/stdint.m4, m4/stdint_h.m4, m4/stdio_h.m4, m4/stdlib_h.m4, m4/stpcpy.m4, m4/strcase.m4, m4/strchrnul.m4, m4/strerror.m4, m4/string_h.m4, m4/strings_h.m4, m4/strndup.m4, m4/strnlen.m4, m4/strverscmp.m4, m4/sys_socket_h.m4, m4/sys_stat_h.m4, m4/sys_time_h.m4, m4/sys_types_h.m4, m4/sys_wait_h.m4, m4/sysexits.m4, m4/tempname.m4, m4/time_h.m4, m4/unistd_h.m4, m4/vasnprintf.m4, m4/vsnprintf.m4, m4/warn-on-use.m4, m4/wchar_h.m4, m4/wchar_t.m4, m4/wctype_h.m4, m4/wint_t.m4, m4/xalloc.m4, m4/xsize.m4, tests/core/randtgba.cc, tools/snippet/arg-nonnull.h, tools/snippet/c++defs.h, tools/snippet/warn-on-use.h: Update.
This commit is contained in:
parent
561672d3d7
commit
f6c7ed54c7
218 changed files with 889 additions and 654 deletions
136
lib/intprops.h
136
lib/intprops.h
|
|
@ -1,10 +1,10 @@
|
|||
/* intprops.h -- properties of integer types
|
||||
|
||||
Copyright (C) 2001-2005, 2009-2015 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001-2016 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
This program is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
|
@ -21,9 +21,9 @@
|
|||
#define _GL_INTPROPS_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <verify.h>
|
||||
|
||||
/* Return an integer value, converted to the same type as the integer
|
||||
expression E after integer type promotion. V is the unconverted value. */
|
||||
/* Return a value with the common real type of E and V and the value of V. */
|
||||
#define _GL_INT_CONVERT(e, v) (0 * (e) + (v))
|
||||
|
||||
/* Act like _GL_INT_CONVERT (E, -V) but work around a bug in IRIX 6.5 cc; see
|
||||
|
|
@ -37,37 +37,18 @@
|
|||
an integer. */
|
||||
#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
|
||||
|
||||
/* True if negative values of the signed integer type T use two's
|
||||
complement, ones' complement, or signed magnitude representation,
|
||||
respectively. Much GNU code assumes two's complement, but some
|
||||
people like to be portable to all possible C hosts. */
|
||||
#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
|
||||
#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
|
||||
#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
|
||||
|
||||
/* True if the signed integer expression E uses two's complement. */
|
||||
#define _GL_INT_TWOS_COMPLEMENT(e) (~ _GL_INT_CONVERT (e, 0) == -1)
|
||||
|
||||
/* True if the arithmetic type T is signed. */
|
||||
/* True if the real type T is signed. */
|
||||
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
|
||||
|
||||
/* Return 1 if the integer expression E, after integer promotion, has
|
||||
a signed type. */
|
||||
#define _GL_INT_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
|
||||
/* Return 1 if the real expression E, after promotion, has a
|
||||
signed or floating type. */
|
||||
#define EXPR_SIGNED(e) (_GL_INT_NEGATE_CONVERT (e, 1) < 0)
|
||||
|
||||
|
||||
/* Minimum and maximum values for integer types and expressions. These
|
||||
macros have undefined behavior if T is signed and has padding bits.
|
||||
If this is a problem for you, please let us know how to fix it for
|
||||
your host. */
|
||||
/* Minimum and maximum values for integer types and expressions. */
|
||||
|
||||
/* The maximum and minimum values for the integer type T. */
|
||||
#define TYPE_MINIMUM(t) \
|
||||
((t) (! TYPE_SIGNED (t) \
|
||||
? (t) 0 \
|
||||
: TYPE_SIGNED_MAGNITUDE (t) \
|
||||
? ~ (t) 0 \
|
||||
: ~ TYPE_MAXIMUM (t)))
|
||||
#define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
|
||||
#define TYPE_MAXIMUM(t) \
|
||||
((t) (! TYPE_SIGNED (t) \
|
||||
? (t) -1 \
|
||||
|
|
@ -76,18 +57,35 @@
|
|||
/* The maximum and minimum values for the type of the expression E,
|
||||
after integer promotion. E should not have side effects. */
|
||||
#define _GL_INT_MINIMUM(e) \
|
||||
(_GL_INT_SIGNED (e) \
|
||||
? - _GL_INT_TWOS_COMPLEMENT (e) - _GL_SIGNED_INT_MAXIMUM (e) \
|
||||
(EXPR_SIGNED (e) \
|
||||
? ~ _GL_SIGNED_INT_MAXIMUM (e) \
|
||||
: _GL_INT_CONVERT (e, 0))
|
||||
#define _GL_INT_MAXIMUM(e) \
|
||||
(_GL_INT_SIGNED (e) \
|
||||
(EXPR_SIGNED (e) \
|
||||
? _GL_SIGNED_INT_MAXIMUM (e) \
|
||||
: _GL_INT_NEGATE_CONVERT (e, 1))
|
||||
#define _GL_SIGNED_INT_MAXIMUM(e) \
|
||||
(((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
|
||||
|
||||
/* This include file assumes that signed types are two's complement without
|
||||
padding bits; the above macros have undefined behavior otherwise.
|
||||
If this is a problem for you, please let us know how to fix it for your host.
|
||||
As a sanity check, test the assumption for some signed types that
|
||||
<limits.h> bounds. */
|
||||
verify (TYPE_MINIMUM (signed char) == SCHAR_MIN);
|
||||
verify (TYPE_MAXIMUM (signed char) == SCHAR_MAX);
|
||||
verify (TYPE_MINIMUM (short int) == SHRT_MIN);
|
||||
verify (TYPE_MAXIMUM (short int) == SHRT_MAX);
|
||||
verify (TYPE_MINIMUM (int) == INT_MIN);
|
||||
verify (TYPE_MAXIMUM (int) == INT_MAX);
|
||||
verify (TYPE_MINIMUM (long int) == LONG_MIN);
|
||||
verify (TYPE_MAXIMUM (long int) == LONG_MAX);
|
||||
#ifdef LLONG_MAX
|
||||
verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
|
||||
verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
|
||||
#endif
|
||||
|
||||
/* Return 1 if the __typeof__ keyword works. This could be done by
|
||||
/* Does the __typeof__ keyword work? This could be done by
|
||||
'configure', but for now it's easier to do it by hand. */
|
||||
#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
|
||||
|| (0x5110 <= __SUNPRO_C && !__STDC__))
|
||||
|
|
@ -224,24 +222,35 @@
|
|||
? (a) < (min) >> (b) \
|
||||
: (max) >> (b) < (a))
|
||||
|
||||
/* True if __builtin_add_overflow (A, B, P) works when P is null. */
|
||||
#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__)
|
||||
|
||||
/* The _GL*_OVERFLOW macros have the same restrictions as the
|
||||
*_RANGE_OVERFLOW macros, except that they do not assume that operands
|
||||
(e.g., A and B) have the same type as MIN and MAX. Instead, they assume
|
||||
that the result (e.g., A + B) has that type. */
|
||||
#define _GL_ADD_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? (b) <= (a) + (b) \
|
||||
: (b) < 0 ? (a) <= (a) + (b) \
|
||||
: (a) + (b) < (b))
|
||||
#define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? 1 \
|
||||
: (b) < 0 ? (a) - (b) <= (a) \
|
||||
: (a) < (b))
|
||||
#define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
|
||||
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|
||||
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
|
||||
#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
|
||||
# define _GL_ADD_OVERFLOW(a, b, min, max)
|
||||
__builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0)
|
||||
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max)
|
||||
__builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0)
|
||||
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max)
|
||||
__builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0)
|
||||
#else
|
||||
# define _GL_ADD_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? (b) <= (a) + (b) \
|
||||
: (b) < 0 ? (a) <= (a) + (b) \
|
||||
: (a) + (b) < (b))
|
||||
# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? INT_SUBTRACT_RANGE_OVERFLOW (a, b, min, max) \
|
||||
: (a) < 0 ? 1 \
|
||||
: (b) < 0 ? (a) - (b) <= (a) \
|
||||
: (a) < (b))
|
||||
# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
|
||||
(((min) == 0 && (((a) < 0 && 0 < (b)) || ((b) < 0 && 0 < (a)))) \
|
||||
|| INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max))
|
||||
#endif
|
||||
#define _GL_DIVIDE_OVERFLOW(a, b, min, max) \
|
||||
((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \
|
||||
: (a) < 0 ? (b) <= (a) + (b) - 1 \
|
||||
|
|
@ -273,9 +282,10 @@
|
|||
|
||||
Example usage, assuming A and B are long int:
|
||||
|
||||
long int result = INT_MULTIPLY_WRAPV (a, b);
|
||||
printf ("result is %ld (%s)\n", result,
|
||||
INT_MULTIPLY_OVERFLOW (a, b) ? "after overflow" : "no overflow");
|
||||
if (INT_MULTIPLY_OVERFLOW (a, b))
|
||||
printf ("result would overflow\n");
|
||||
else
|
||||
printf ("result is %ld (no overflow)\n", a * b);
|
||||
|
||||
Example usage with WRAPV flavor:
|
||||
|
||||
|
|
@ -305,8 +315,12 @@
|
|||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
|
||||
#define INT_SUBTRACT_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
|
||||
#define INT_NEGATE_OVERFLOW(a) \
|
||||
INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
|
||||
#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
|
||||
# define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
|
||||
#else
|
||||
# define INT_NEGATE_OVERFLOW(a) \
|
||||
INT_NEGATE_RANGE_OVERFLOW (a, _GL_INT_MINIMUM (a), _GL_INT_MAXIMUM (a))
|
||||
#endif
|
||||
#define INT_MULTIPLY_OVERFLOW(a, b) \
|
||||
_GL_BINARY_OP_OVERFLOW (a, b, _GL_MULTIPLY_OVERFLOW)
|
||||
#define INT_DIVIDE_OVERFLOW(a, b) \
|
||||
|
|
@ -326,7 +340,7 @@
|
|||
_GL_INT_MINIMUM (0 * (b) + (a)), \
|
||||
_GL_INT_MAXIMUM (0 * (b) + (a)))
|
||||
|
||||
/* Compute A + B, A - B, A * B, respectively, storing the result into *R.
|
||||
/* Store the low-order bits of A + B, A - B, A * B, respectively, into *R.
|
||||
Return 1 if the result overflows. See above for restrictions. */
|
||||
#define INT_ADD_WRAPV(a, b, r) \
|
||||
_GL_INT_OP_WRAPV (a, b, r, +, __builtin_add_overflow, INT_ADD_OVERFLOW)
|
||||
|
|
@ -351,10 +365,11 @@
|
|||
# define _GL__GENERIC_BOGUS 0
|
||||
#endif
|
||||
|
||||
/* Store A <op> B into *R, where OP specifies the operation.
|
||||
BUILTIN is the builtin operation, and OVERFLOW the overflow predicate.
|
||||
See above for restrictions. */
|
||||
#if 5 <= __GNUC__ || __has_builtin (__builtin_add_oveflow)
|
||||
/* Store the low-order bits of A <op> B into *R, where OP specifies
|
||||
the operation. BUILTIN is the builtin operation, and OVERFLOW the
|
||||
overflow predicate. Return 1 if the result overflows. See above
|
||||
for restrictions. */
|
||||
#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow)
|
||||
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r)
|
||||
#elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
|
||||
# define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
|
||||
|
|
@ -404,14 +419,15 @@
|
|||
/* Store the low-order bits of A <op> B into *R, where the operation
|
||||
is given by OP. Use the unsigned type UT for calculation to avoid
|
||||
overflow problems. *R's type is T, with extremal values TMIN and
|
||||
TMAX. T must be a signed integer type. */
|
||||
TMAX. T must be a signed integer type. Return 1 if the result
|
||||
overflows. */
|
||||
#define _GL_INT_OP_CALC(a, b, r, op, overflow, ut, t, tmin, tmax) \
|
||||
(sizeof ((a) op (b)) < sizeof (t) \
|
||||
? _GL_INT_OP_CALC1 ((t) (a), (t) (b), r, op, overflow, ut, t, tmin, tmax) \
|
||||
: _GL_INT_OP_CALC1 (a, b, r, op, overflow, ut, t, tmin, tmax))
|
||||
#define _GL_INT_OP_CALC1(a, b, r, op, overflow, ut, t, tmin, tmax) \
|
||||
((overflow (a, b) \
|
||||
|| (_GL_INT_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \
|
||||
|| (EXPR_SIGNED ((a) op (b)) && ((a) op (b)) < (tmin)) \
|
||||
|| (tmax) < ((a) op (b))) \
|
||||
? (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 1) \
|
||||
: (*(r) = _GL_INT_OP_WRAPV_VIA_UNSIGNED (a, b, op, ut, t, tmin, tmax), 0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue