summaryrefslogtreecommitdiff
path: root/lib/intprops.h
Commit message (Collapse)AuthorAgeFilesLines
* maint: run 'make update-copyright'Simon Josefsson2023-01-011-1/+1
|
* maint: parenthesize macro definiensPaul Eggert2022-08-101-3/+3
| | | | | | | | * lib/intprops.h (INT_ADD_OK, INT_SUBTRACT_OK, INT_MULTIPLY_OK): * lib/pipe-filter-ii.c (GetLastError): * lib/thread-optim.h (gl_multithreaded): Parenthesize function-like macro definiens beginning with a unary operator; needed for weird invocations like ‘m (...)[p]’.
* stdckdint-h: new modulePaul Eggert2022-08-101-2/+9
| | | | | | | | | | | | | | | | | | | | | | | This supports draft C23 <stdckdint.h>. * doc/posix-headers/stdckdint.texi: * lib/stdckdint.in.h, modules/stdckdint: * modules/stdckdint-tests, tests/test-stdckdint.c: New files. * MODULES.html.sh, doc/gnulib.texi: Update for new module. * lib/intprops-internal.h: Include <stdckdint.h> if C23 and its macros would help and our substitute has not already started to be included. (_GL_INT_ADD_WRAPV, _GL_INT_SUBTRACT_WRAPV) (_GL_INT_MULTIPLY_WRAPV): Use ckd_add, ckd_sub, ckd_mul if they are defined and would help. * lib/intprops-internal.h, lib/intprops.h: Improve comments. The C23 restrictions on stdckdint macros already mostly applied to intprops.h, so these are clarifications, not further restrictions. * tests/test-intprops.c: If TEST_STDCKDINT is defined, include <stdckdint.h> instead of "intprops.h", and test it instead. (VERIFY) [TEST_STDCKDINT]: Ignore the arg in this case. (main) [TEST_STDCKDINT]: Skip tests irrelevant to stdckdint.h.
* intprops: refactor intprops.h into twoPaul Eggert2022-08-101-323/+9
| | | | | | | | | | | | | | | | | | | | * lib/intprops.h: Include new file intprops-internal.h. (_GL_INT_CONVERT, _GL_INT_NEGATE_CONVERT, _GL_INT_MINIMUM) (_GL_INT_MAXIMUM, _GL_SIGNED_INT_MAXIMUM, LLONG_MAX, LLONG_MIN) (_GL_HAVE___TYPEOF__, _GL_SIGNED_TYPE_OR_EXPR) (_GL_HAS_BUILTIN_ADD_OVERFLOW, _GL_HAS_BUILTIN_MUL_OVERFLOW) (_GL_HAS_BUILTIN_OVERFLOW_P, _GL__GENERIC_BOGUS) (_GL_INT_OP_WRAPV, _GL_INT_OP_WRAPV_LONGISH, _GL_INT_OP_CALC) (_GL_INT_OP_WRAPV_VIA_UNSIGNED, _GL_INT_ADD_RANGE_OVERFLOW) (_GL_INT_SUBTRACT_RANGE_OVERFLOW) (_GL_INT_MULTIPLY_RANGE_OVERFLOW): Move to intprops-internal.h. (TYPE_SIGNED, EXPR_SIGNED, TYPE_WIDTH, INT_NEGATE_RANGE_OVERFLOW) (INT_NEGATE_OVERFLOW, INT_ADD_WRAPV, INT_SUBTRACT_WRAPV) (INT_MULTIPLY_WRAPV): Rename to _GL_ prefix, move to intprops-internal.h, and define here in terms of the _GL_ name. * lib/intprops-internal.h: New file, containing the above. * modules/intprops (Files): Add lib/intprops-internal.h.
* intprops: refactor _GL_HAS_BUILTIN_OVERFLOW_PPaul Eggert2022-08-101-7/+7
| | | | | | | * 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.
* intprops: work around nvc 22.1 bugPaul Eggert2022-01-141-2/+6
| | | | | | | Problem reported by Olivier Cessenat (Bug#53256). * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW) [__EDG__]: Define to 0, since __builtin_add_overflow doesn’t work on NVIDIA HPC SDK 22.1.
* maint: run 'make update-copyright'Paul Eggert2022-01-011-1/+1
|
* maint: fix __clang_major__ misspellingsPaul Eggert2021-12-211-1/+1
| | | | | | | | | | The intprops.h typo fix should fix a bug in Emacs on Debian testing with clang <https://bugs.gnu.org/52711>. * lib/asyncsafe-spin.c, lib/intprops.h, lib/pthread-spin.c: Fix some misspellings of ‘__clang_major__’. I left one misspelling alone, in lib/cdefs.h, and instead reported that bug upstream here: https://sourceware.org/pipermail/libc-alpha/2021-December/134512.html
* intprops: streamline and get ready for Clang 14Paul Eggert2021-12-061-11/+9
| | | | | | | | | | | | * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Rely on __has_builtin first, since GCC didn’t introduce it until GCC 9 so we don’t need to special-case GCC first. (_GL_HAS_BUILTIN_ADD_OVERFLOW, _GL_HAS_BUILTIN_OVERFLOW_P): Look at __EDG__ rather than __ICC, since icc defines __EDG__ too. (_GL_HAS_BUILTIN_MUL_OVERFLOW): Define to 1 in Clang 14 and later, as a bug fix is scheduled for Clang 14. (_GL_HAS_BUILTIN_OVERFLOW_P): Do not bother to special-case __clang__, since __has_builtin should do the right thing anyway.
* intprops: Treat EDG-based compilers like Intel compilers.Bruno Haible2021-12-061-4/+5
| | | | | | | | Reported by Ilya Kurdyukov <ilyakurdyukov@altlinux.org> in <https://lists.gnu.org/archive/html/bug-gnulib/2021-12/msg00028.html>. * lib/intprops.h (_GL_HAS_BUILTIN_OVERFLOW_P): Define to 0 on EDG-based compilers.
* 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.