summaryrefslogtreecommitdiff
path: root/lib/intprops.h
Commit message (Collapse)AuthorAgeFilesLines
* regex: sync with glibcPaul Eggert2021-09-211-1/+0
| | | | | | * config/srclist.txt: Uncomment-out posix/regex.c and related files, as the Gnulib versions have now been copied to glibc. * lib/intprops.h: Remove authorship comment, as per glibc guidelines.
* intprops: improve commentaryPaul Eggert2021-03-141-4/+14
| | | | * lib/intprops.h: Improve comments about promotion etc.
* maint: run 'make update-copyright'Paul Eggert2020-12-311-1/+1
|
* intprops: port to ICC 2021.1 Beta 20201112Paul Eggert2020-12-181-5/+10
| | | | | | | | | | * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P): Port to ICC 2021.1, which has a non-working __builtin_mul_overflow_p. Add a clause for other compilers that claim to support __builtin_mul_overflow_p, since we might as well find out about slackers other than Clang and ICC. (INT_MULTIPLY_WRAPV): ICC 2021 has GCC bug 91450, so treat it like older GCCs even when it claims to be a newer one.
* intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.Bruno Haible2020-12-181-1/+3
| | | | | | | | | | Reported by Stefan Liebler <stli@linux.ibm.com> in <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>. * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for GCC 5.x and 6.x. * lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for GCC 5.x and 6.x.
* intprops: Add INT_ADD_OK etc.Paul Eggert2020-12-051-0/+29
| | | | | | | * doc/intprops.texi (Checking Integer Overflow): New section. * lib/intprops.h: From a suggestion by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2020-12/msg00051.html (SAFE_INT_ADD, SAFE_INT_SUBTRACT, SAFE_INT_MULTIPLY): New macros.
* intprops, xalloc: avoid __builtin_mul_overflow_p with ClangPaul Eggert2020-09-171-1/+7
| | | | | | | | | Problem reported by Nelson H. F. Beebe for clang 9.0.1 in: https://lists.gnu.org/r/grep-devel/2020-09/msg00028.html * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P) [__clang__]: Define to 0. * lib/xalloc-oversized.h (xalloc_oversized) [__clang__]: Do not use __builtin_mul_overflow_p.
* intprops: be consistent about +X vs X+0Paul Eggert2020-08-231-1/+1
| | | | * lib/intprops.h (_GL_SIGNED_INT_MAXIMUM): Simplify.
* intprops: fix INT_MULTIPLY_WRAPV bit-field bugPaul Eggert2020-08-231-5/+8
| | | | | | | | | | The bug occurs when using INT_MULTIPLY_WRAPV (a, b, c) where B is a bit-field, on older GCC or non-GCC compilers where we do things ourselves instead of using __builtin_mul_overflow. Without this fix, INT_MULTIPLY_WRAPV would not compile, due to applying sizeof to a bit-field. * lib/intprops.h (_GL_INT_MULTIPLY_RANGE_OVERFLOW): Promote B before giving it to TYPE_WIDTH, in case B is a bit-field.
* intprops: Avoid bogus "warning: division by zero is undefined" on clang.Bruno Haible2020-08-161-1/+1
| | | | * lib/intprops.h (_GL__GENERIC_BOGUS): Define to 1 on clang.
* Revert autoupdate's revert.Bruno Haible2020-08-101-1/+2
| | | | * config/srclist.txt: Mark intprops.h as needing sync with glibc.
* autoupdateKarl Berry2020-08-101-2/+1
|
* Use __typeof__ with clang.Bruno Haible2020-08-091-0/+1
| | | | | | | | * m4/stdint.m4 (gl_STDINT_H): Check for SIZE_MAX also on "clang -std=gnu99". * lib/intprops.h (_GL_HAVE___TYPEOF__): Define to 1 also on clang. * tests/test-stdint.c (verify_same_types): Enable the check also on clang.
* intprops: Fix typo in comment.Bruno Haible2020-08-091-1/+1
| | | | * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P): Fix typo in comment.
* maint: Run 'make update-copyright'Paul Eggert2019-12-311-1/+1
|
* intprops: INT_MULTIPLY_WRAPV speedup for GCC 8.4+Paul Eggert2019-11-221-1/+2
| | | | | | * lib/intprops.h (INT_MULTIPLY_WRAPV): If GCC 8.x where 4 <= x, remove workaround for GCC bug 91450 as the bug should be fixed there too.
* * lib/intprops.h (INT_MULTIPLY_WRAPV): Simplify gcc -E output.Paul Eggert2019-11-191-7/+10
|
* intprops: speed up INT_MULTIPLY_WRAPV in GCC 9.3Paul Eggert2019-11-191-2/+3
| | | | | * lib/intprops.h (INT_MULTIPLY_WRAPV): If GCC 9.3 or later, do not work around GCC bug 91450 as the bug should be fixed there.
* Port better to GCC under macOSPaul Eggert2019-10-231-19/+3
| | | | | | | | | | | | | | | | | | | | Work around macOS header that has ‘#define __has_builtin(x) 0’ when compiled by GCC. Apple really, really doesn’t want you to use GCC, apparently. Rroblem reported by Akim Demaille in: https://lists.gnu.org/r/bug-bison/2019-10/msg00071.html The fix is to not trust __has_builtin when being compiled by recent-enough GCC. * lib/intprops.h (__has_builtin) (_GL_HAS___builtin_add_overflow, _GL_TEMPDEF___has_builtin): * lib/verify.h (__has_builtin, _GL_HAS___builtin_unreachable) (_GL_HAS___builtin_trap, _GL_TEMPDEF___has_builtin): Remove. All uses removed. * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Use __has_builtin directly, if defined and if not newer GCC. * lib/verify.h (_GL_HAS_BUILTIN_TRAP, _GL_HAS_BUILTIN_UNREACHABLE): New macro, that use __has_builtin directly, if defined and if not newer GCC. (assume): Use them.
* Revert macOS INT_MULTIPLY_WRAPV patchPaul Eggert2019-08-271-8/+5
| | | | | | | | Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2019-08/msg00076.html * lib/intprops.h (_GL_HAS___builtin_mul_overflow): Remove. (_GL_HAS_BUILTIN_MUL_OVERFLOW): Go back to working around the Clang bug on macOS.
* Speed up INT_MULTIPLY_WRAPV on macOSPaul Eggert2019-08-271-5/+8
| | | | | | | | | | Assume that __builtin_mul_overflow works OK with Clang on macOS. Mattias Engdegård says it’s safe to assume the relevant library is always available there. * lib/intprops.h (_GL_HAS___builtin_mul_overflow): New temporary internal macro. (_GL_HAS_BUILTIN_MUL_OVERFLOW): No need to work around the Clang bug on macOS.
* intprops.h, verify.h: port better to clangPaul Eggert2019-08-251-33/+60
| | | | | | | | | | | | | | | | | | | | | | | Improve code generated by INT_ADD_WRAPV and INT_SUBTRACT_WRAPV with Clang. Problem reported privately by Mattias Engdegård. Also, insulate intprops.h and verify.h better against each other’s definitions of __has_builtin on non-Clang hosts. * lib/intprops.h (__has_builtin): Define a temporary substitute if __has_builtin is not already defined. (_GL_HAS___builtin_add_overflow, _GL_TEMPDEF___has_builtin): New temporary internal macros. (_GL_HAS_BUILTIN_ADD_OVERFLOW, _GL_HAS_BUILTIN_MUL_OVERFLOW): Now two separate macros, replacing the old _GL_HAS_BUILTIN_OVERFLOW, since we no longer assume that __builtin_mul_overflow is like the rest. All uses changed. (INT_ADD_WRAPV, INT_SUBTRACT_WRAPV, INT_MULTIPLY_WRAPV): Adjust to above changes. (_GL_INT_OP_WRAPV): Remove ‘builtin’ arg, since it’s no longer relevant. All uses changed. * lib/verify.h (__has_builtin): Treat like intprops.h, so that the two .h files do not collide with each other. (_GL_HAS___builtin_unreachable, _GL_HAS___builtin_trap) (_GL_TEMPDEF___has_builtin): New temporary internal macros.
* intprops: say why not Clang __builtin_add_overflowPaul Eggert2019-08-241-1/+3
| | | | | | * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW): Mention Clang in comment, responding to a query from Mattias Engdegård.
* intprops: port to Oracle Developer Studio 12.6Paul Eggert2019-08-171-2/+2
| | | | | * lib/intprops.h (_GL_INT_OP_WRAPV): Fix recently-introduced typos that were in a section not compiled by GCC.
* intprops: support uchar, ushort _WRAPV destsPaul Eggert2019-08-141-21/+32
| | | | | | | | * lib/intprops.h (_GL_INT_OP_WRAPV_SMALLISH): New macro, defined when __builtin_add_overflow etc. and _Generic are not used. (_GL_INT_OP_WRAPV): Use it to support destinations that are unsigned char or unsigned short, even in compilers that lack __typeof__ and are not C11-compatible.
* intprops: pacify picky GCCPaul Eggert2019-08-141-2/+4
| | | | | | | | * lib/intprops.h (_GL_BUILTIN_MUL_OVERFLOW): Pacify GCC’s complaints about ignoring __builtin_mul_overflow’s possibly-incorrect result. (_GL_INT_MULTIPLY_RANGE_OVERFLOW): Pacify GCC’s complaints about (A) used as a boolean, when A is an expression like 3 * 4.
* intprops: support unsigned *_WRAPV resultsPaul Eggert2019-08-141-28/+126
| | | | | | | | | | | | | | | | | | | | | Add support for unsigned, unsigned long, and unsigned long long results to INT_ADD_WRAPV, INT_SUBTRACT_WRAPV, and INT_MULTIPLY_WRAPV. Also, work around GCC bug 91450, and fix a bug with unsigned inputs reported by Eli Zaretskii in: https://lists.gnu.org/r/bug-gnulib/2019-08/msg00012.html * config/srclist.txt: Break the glibc connection for intprops.h temporarily, while more testing is done in Gnulib-using apps. * lib/intprops.h (INT_ADD_WRAPV, INT_SUBTRACT_WRAPV) (INT_MULTIPLY_WRAPV, _GL_INT_OP_WRAPV, _GL_INT_OP_WRAPV_LONGISH): Support unsigned results no narrower than unsigned int. Report overflow correctly if some arguments are unsigned. (_GL_BUILTIN_MUL_OVERFLOW): New macro, to work around GCC bug 91450. (_GL_INT_OP_CALC): Simplify now that the OVERFLOW argument does the right thing with narrow args. (_GL_INT_OP_CALC1): Remove. All callers removed. (_GL_INT_ADD_RANGE_OVERFLOW, _GL_INT_SUBTRACT_RANGE_OVERFLOW) (_GL_INT_MULTIPLY_RANGE_OVERFLOW): New macros. * tests/test-intprops.c: Check for bugs and test new behavior.
* autoupdatePaul Eggert2018-12-311-1/+1
|
* intprops: minor clarification of codePaul Eggert2018-09-071-2/+2
| | | | | * lib/intprops.h (_GL_BINARY_OP_OVERFLOW): Use _GL_INT_CONVERT rather than reinventing it.
* intprops: avoid evaluation of some expressionsPaul Eggert2018-08-271-7/+9
| | | | | | | | | This makes EXPR_SIGNED (e) easier to use, as it no longer evaluates the expression E. Formerly, E was required to be free of side effects. * lib/intprops.h (_GL_INT_CONVERT, _GL_INT_NEGATE_CONVERT) (EXPR_SIGNED, TYPE_WIDTH, _GL_INT_MINIMUM, _GL_INT_MAXIMUM) (_GL_SIGNED_INT_MAXIMUM): Do not evaluate the expression arg.
* maint: Run 'make update-copyright'Paul Eggert2018-01-011-1/+1
|
* maint: shorten https://lists.gnu.org/archive/html/... linksJim Meyering2017-11-121-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Each /archive/html/ part can be replace with /r/. Run this to induce the change: git grep -l archive/html|xargs perl -pi -e 's,/archive/html/,/r/,g' * ChangeLog: Perform that substitution. * Makefile: Likewise. * STATUS-libposix: Likewise. * build-aux/bootstrap: Likewise. * doc/maintain.texi: Likewise. * gnulib-tool: Likewise. * lib/allocator.h: Likewise. * lib/argp-ba.c: Likewise. * lib/argp-pv.c: Likewise. * lib/canon-host.c: Likewise. * lib/canonicalize-lgpl.c: Likewise. * lib/float.in.h: Likewise. * lib/fstat.c: Likewise. * lib/getdelim.c: Likewise. * lib/getprogname.c: Likewise. * lib/glthread/thread.h: Likewise. * lib/intprops.h: Likewise. * lib/mbsrtowcs-state.c: Likewise. * lib/safe-read.c: Likewise. * lib/signal.in.h: Likewise. * lib/stat.c: Likewise. * lib/stdbool.in.h: Likewise. * lib/stdio-impl.h: Likewise. * lib/stdio.in.h: Likewise. * lib/sysexits.in.h: Likewise. * lib/timespec.h: Likewise. * lib/wcsrtombs-state.c: Likewise. * m4/alloca.m4: Likewise. * m4/extern-inline.m4: Likewise. * m4/fstatat.m4: Likewise. * m4/gnulib-common.m4: Likewise. * m4/lib-ignore.m4: Likewise. * m4/printf.m4: Likewise. * m4/regex.m4: Likewise. * m4/stat-size.m4: Likewise. * m4/std-gnu11.m4: Likewise. * m4/stdbool.m4: Likewise. * m4/sys_types_h.m4: Likewise. * m4/threadlib.m4: Likewise. * m4/vararrays.m4: Likewise. * pygnulib/GLImport.py: Likewise. * tests/test-exp.h: Likewise. * tests/test-exp2.h: Likewise. * tests/test-expm1.h: Likewise. * tests/test-fflush2.c: Likewise. * tests/test-getopt_long.h: Likewise. * tests/test-intprops.c: Likewise. * tests/test-log.h: Likewise. * tests/test-log10.h: Likewise. * tests/test-log1p.h: Likewise. * tests/test-log2.h: Likewise. * tests/test-printf-posix.h: Likewise. * tests/test-regex.c: Likewise. * tests/test-snprintf-posix.h: Likewise. * tests/test-sprintf-posix.h: Likewise. * tests/test-stdalign.c: Likewise. * tests/test-stdbool.c: Likewise. * tests/test-vasnprintf-posix.c: Likewise. * tests/test-vasprintf-posix.c: Likewise. * top/maint.mk: Likewise.
* all: Replace many more http URLs by https URLs. Update stale URLs.Bruno Haible2017-09-141-3/+3
| | | | | * users.txt: Remove mention of 'newts'. * lib/localename.c: Update comment about LANG_SOTHO.
* all: prefer https: URLsPaul Eggert2017-09-131-1/+1
|
* intprops: port to recent iccPaul Eggert2017-05-251-1/+5
| | | | | | | Port to icc (ICC) 17.0.4 20170411, which defines __GNUC__ to be 5 but does not support __builtin_add_overflow etc. * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW) [__ICC]: Define to 0.
* intprops: don’t depend on ‘verify’Paul Eggert2017-05-081-19/+1
| | | | | | | | | | Problem reported by Ævar Arnfjörð Bjarmason in: http://lists.gnu.org/archive/html/bug-gnulib/2017-05/msg00054.html * lib/intprops.h: Do not include verify.h, and move compile-time checks from here ... * tests/test-intprops.c (main): ... to here, if they’re not here already. Check widths of other standard integer types. * modules/intprops (Depends-on): Remove ‘verify’.
* intprops: improve commentsPaul Eggert2017-04-151-20/+13
| | | | | | | | | | | | | | | * lib/intprops.h: Improve and shorten commentary. For the record, if we ever run into a pedantic compiler that behaves differently from GCC when converting an out-of-range value to a signed integer, we can work around the problem with something like the following code, where UCT is the signed counterpart of T (UCT is sometimes narrower than UT) and all callers are changed accordingly: ((t) ((ut) (a) op (ut) (b))) (TYPE_MINIMUM (t) <= (uct) ((ut) (a) op (ut) (b)) \ ? ((t) (uct) (((ut) (a) op (ut) (b)) - TYPE_MINIMUM (t)) \ + TYPE_MINIMUM (t)) \ : (t) (uct) ((ut) (a) op (ut) (b)))
* intprops: fix comment typoPaul Eggert2017-04-141-2/+2
|
* intprops: try to avoid tickling similar bugsPaul Eggert2017-04-141-10/+9
| | | | | | | * lib/intprops.h (_GL_INT_OP_CALC): Document that UT no longer needs to be the same width as T; it can be wider. Change callers so that UT is at least as wide as unsigned int, as I suspect that this is less likely to run into compiler bugs.
* intprops: port to Oracle Studio 12.3 x86Paul Eggert2017-04-141-12/+29
| | | | | | | | Problem reported by Gavin Smith in: http://lists.gnu.org/archive/html/bug-gnulib/2017-04/msg00049.html * lib/intprops.h (_GL_INT_OP_WRAPV_VIA_UNSIGNED): Convert unsigned to signed via the usual rather than the standard way, to avoid a compiler bug in Oracle Studio 12.3 x86.
* glob, intprops, xalloc: work around Clang bugPaul Eggert2017-01-061-8/+2
| | | | | | | | | | | | Work around LLVM bug 16404, which is still not fixed. https://llvm.org/bugs/show_bug.cgi?id=16404 Problem reported by Nelson H. F. Beebe. * lib/glob.c, lib/intprops.h, lib/xalloc-oversized.h (__has_builtin): Remove. * lib/glob.c (size_add_wrapv): * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P): * lib/xalloc-oversized.h (xalloc_oversized): Do not use overflow builtins if Clang.
* version-etc: new yearPaul Eggert2017-01-011-1/+1
| | | | | | | | | | * build-aux/gendocs.sh (version): * doc/gendocs_template: * doc/gendocs_template_min: * doc/gnulib.texi: * lib/version-etc.c (COPYRIGHT_YEAR): Update copyright dates by hand in templates and the like. * all files: Run 'make update-copyright'.
* intprops: port to older XL CPaul Eggert2016-11-031-1/+2
| | | | | | | | | Problem reported by Alexander Samoilov in: http://lists.gnu.org/archive/html/bug-gnulib/2016-10/msg00166.html http://savannah.nongnu.org/bugs/?49448 * lib/intprops.h (_GL_HAVE___TYPEOF__) [__IBM__TYPEOF__]: Define to 1 only for XL C 12.1 or later, since this bug occurs in XL C for AIX 6.0 but not in 12.1.
* intprops: new macro TYPE_WIDTHPaul Eggert2016-09-131-4/+11
| | | | | | | | * lib/intprops.h (TYPE_WIDTH): New macro. (TYPE_MAXIMUM, _GL_SIGNED_INT_MAXIMUM, INT_STRLEN_BOUND): * lib/ftoastr.h (_GL_FLOAT_DIG_BITS_BOUND): * lib/parse-datetime.y (parse_datetime2): Use it.
* intprops: tune INT_NEGATE_OVERFLOW for GCC 5 and 6Paul Eggert2016-08-301-1/+1
| | | | | | | | | | * lib/intprops.h (INT_NEGATE_OVERFLOW): Tune for platforms like GCC 5 and 6 that have __builtin_sub_overflow but not __builtin_sub_overflow_p. With the recent changes, these platforms are a tiny bit faster with the INT_NEGATE_RANGE_OVERFLOW implementation than with INT_SUBTRACT_OVERFLOW implementation, since the former needs just one runtime comparison whereas the latter needs two.
* intprops.h: port recent changes to GCC 6.2.0Paul Eggert2016-08-291-16/+11
| | | | | | | | | | | | | * lib/intprops.h (__has_builtin): Move earlier. (_GL_HAS_BUILTIN_OVERFLOW): Rename from _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL and don't worry about whether the last argument can be null. All uses changed. (_GL_HAS_BUILTIN_OVERFLOW_P): Also test __has_builtin. (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW, _GL_MULTIPLY_OVERFLOW): Don't try to use 3rd arg null, as this doesn't work on GCC 6.2.0 and it's not clear which GCC versions it works for. (_GL_INT_OP_WRAPV): Use _GL_HAS_BUILTIN_OVERFLOW instead of its definiens.
* intprops.h: use __typeof__ with GCC 7Paul Eggert2016-08-291-3/+3
| | | | | | * lib/intprops.h (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW) (_GL_MULTIPLY_OVERFLOW): Use __typeof__ as in the GCC manual. This avoids computing the expression's value (which might overflow!).
* intprops.h, xalloc-oversized.h: work with gcc 7Jim Meyering2016-08-291-2/+12
| | | | | | | | | | | | | | | In gcc 6, __builtin_add_overflow, __builtin_sub_overflow and __builtin_mul_overflow each accept a NULL pointer as the third argument. However in gcc 7, that is no longer accepted. Instead, one must use the "_p"-suffixed names, with which, the third parameter is no longer a pointer. * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_WITH_NULL): Correct the definition: not true for gcc 7 and subsequent. (_GL_HAS_BUILTIN_OVERFLOW_P): Define. (_GL_ADD_OVERFLOW, _GL_SUBTRACT_OVERFLOW, _GL_MULTIPLY_OVERFLOW): Provide new definitions for gcc 7 and subsequent. * lib/xalloc-oversized.h (xalloc_oversized): Provide a definition that works with gcc-7.
* intprops.h: fix missing-backslash problemsJim Meyering2016-08-291-3/+3
| | | | | * lib/intprops.h (_GL_ADD_OVERFLOW): Add backslash. (_GL_SUBTRACT_OVERFLOW,_GL_MULTIPLY_OVERFLOW): Likewise.
* intprops: fix paren typo on old platformsPaul Eggert2016-08-241-1/+1
| | | | | | | | | Problem reported by John E. Malmberg in: https://bugs.gnu.org/24300#13 * lib/intprops.h (_GL_INT_OP_WRAPV_LONGISH) [__GNUC__ < 5 && !__has_builtin (__builtin_add_overflow) && (__STDC_VERSION__ < 201112 || _GL__GENERIC_BOGUS) && !defined LLONG_MAX]: Remove stray paren.