aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2019-10-24 14:32:06 -0700
committerPaul Eggert2019-10-24 14:35:06 -0700
commit4a083b0d36a8b2afe23447dbc357de3641140d4d (patch)
tree4a36c261a476fae4d8143e2692789e236e05fa08 /lib
parent57162dbc065a3b9f9b8dfd555ef628e639061839 (diff)
downloademacs-4a083b0d36a8b2afe23447dbc357de3641140d4d.tar.gz
emacs-4a083b0d36a8b2afe23447dbc357de3641140d4d.zip
Update from Gnulib
This incorporates: 2019-10-23 nstrftime: speed up integer overflow checking 2019-10-23 port better to GCC under macOS 2019-10-15 inttypes: use more-robust test for int range 2019-10-14 update-copyright: use en dashes in .texi ranges * build-aux/update-copyright, lib/intprops.h, lib/inttypes.in.h: * lib/nstrftime.c, lib/verify.h: Copy from Gnulib.
Diffstat (limited to 'lib')
-rw-r--r--lib/intprops.h22
-rw-r--r--lib/inttypes.in.h6
-rw-r--r--lib/nstrftime.c19
-rw-r--r--lib/verify.h37
4 files changed, 28 insertions, 56 deletions
diff --git a/lib/intprops.h b/lib/intprops.h
index 36c6359a21f..bf561ad0a6e 100644
--- a/lib/intprops.h
+++ b/lib/intprops.h
@@ -22,18 +22,6 @@
22 22
23#include <limits.h> 23#include <limits.h>
24 24
25/* If the compiler lacks __has_builtin, define it well enough for this
26 source file only. */
27#ifndef __has_builtin
28# define __has_builtin(x) _GL_HAS_##x
29# if 5 <= __GNUC__ && !defined __ICC
30# define _GL_HAS___builtin_add_overflow 1
31# else
32# define _GL_HAS___builtin_add_overflow 0
33# endif
34# define _GL_TEMPDEF___has_builtin
35#endif
36
37/* Return a value with the common real type of E and V and the value of V. 25/* Return a value with the common real type of E and V and the value of V.
38 Do not evaluate E. */ 26 Do not evaluate E. */
39#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v)) 27#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
@@ -234,8 +222,10 @@
234 222
235/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow 223/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
236 (A, B, P) work when P is non-null. */ 224 (A, B, P) work when P is non-null. */
237#if __has_builtin (__builtin_add_overflow) 225#if 5 <= __GNUC__ && !defined __ICC
238# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1 226# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
227#elif defined __has_builtin
228# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
239#else 229#else
240# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0 230# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
241#endif 231#endif
@@ -586,10 +576,4 @@
586 : (tmin) / (a) < (b)) \ 576 : (tmin) / (a) < (b)) \
587 : (tmax) / (b) < (a))) 577 : (tmax) / (b) < (a)))
588 578
589#ifdef _GL_TEMPDEF___has_builtin
590# undef __has_builtin
591# undef _GL_HAS___builtin_add_overflow
592# undef _GL_TEMPDEF___has_builtin
593#endif
594
595#endif /* _GL_INTPROPS_H */ 579#endif /* _GL_INTPROPS_H */
diff --git a/lib/inttypes.in.h b/lib/inttypes.in.h
index 31e40c51a68..49bcbc168f7 100644
--- a/lib/inttypes.in.h
+++ b/lib/inttypes.in.h
@@ -49,15 +49,15 @@
49#ifndef __GLIBC__ 49#ifndef __GLIBC__
50# include <stdint.h> 50# include <stdint.h>
51#endif 51#endif
52/* Get CHAR_BIT. */ 52/* Get CHAR_BIT, INT_MAX, LONG_MAX, etc. */
53#include <limits.h> 53#include <limits.h>
54/* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */ 54/* On mingw, __USE_MINGW_ANSI_STDIO only works if <stdio.h> is also included */
55#if defined _WIN32 && ! defined __CYGWIN__ 55#if defined _WIN32 && ! defined __CYGWIN__
56# include <stdio.h> 56# include <stdio.h>
57#endif 57#endif
58 58
59#if !(INT_MIN == INT32_MIN && INT_MAX == INT32_MAX) 59#if !(INT_MAX == 0x7fffffff && INT_MIN + INT_MAX == -1)
60# error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>." 60# error "This file assumes that 'int' is 32-bit two's complement. Please report your platform and compiler to <bug-gnulib@gnu.org>."
61#endif 61#endif
62 62
63/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 63/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
diff --git a/lib/nstrftime.c b/lib/nstrftime.c
index bc84da5a0cb..461dadb2929 100644
--- a/lib/nstrftime.c
+++ b/lib/nstrftime.c
@@ -68,6 +68,8 @@ extern char *tzname[];
68#include <string.h> 68#include <string.h>
69#include <stdbool.h> 69#include <stdbool.h>
70 70
71#include <intprops.h>
72
71#ifndef FALLTHROUGH 73#ifndef FALLTHROUGH
72# if __GNUC__ < 7 74# if __GNUC__ < 7
73# define FALLTHROUGH ((void) 0) 75# define FALLTHROUGH ((void) 0)
@@ -113,13 +115,6 @@ extern char *tzname[];
113 ? (a) >> (b) \ 115 ? (a) >> (b) \
114 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0)) 116 : (a) / (1 << (b)) - ((a) % (1 << (b)) < 0))
115 117
116/* Bound on length of the string representing an integer type or expression T.
117 Subtract 1 for the sign bit if t is signed; log10 (2.0) < 146/485;
118 add 1 for integer division truncation; add 1 more for a minus sign
119 if needed. */
120#define INT_STRLEN_BOUND(t) \
121 ((sizeof (t) * CHAR_BIT - 1) * 146 / 485 + 2)
122
123#define TM_YEAR_BASE 1900 118#define TM_YEAR_BASE 1900
124 119
125#ifndef __isleap 120#ifndef __isleap
@@ -704,15 +699,9 @@ __strftime_internal (STREAM_OR_CHAR_T *s, STRFTIME_ARG (size_t maxsize)
704 width = 0; 699 width = 0;
705 do 700 do
706 { 701 {
707 if (width > INT_MAX / 10 702 if (INT_MULTIPLY_WRAPV (width, 10, &width)
708 || (width == INT_MAX / 10 && *f - L_('0') > INT_MAX % 10)) 703 || INT_ADD_WRAPV (width, *f - L_('0'), &width))
709 /* Avoid overflow. */
710 width = INT_MAX; 704 width = INT_MAX;
711 else
712 {
713 width *= 10;
714 width += *f - L_('0');
715 }
716 ++f; 705 ++f;
717 } 706 }
718 while (ISDIGIT (*f)); 707 while (ISDIGIT (*f));
diff --git a/lib/verify.h b/lib/verify.h
index 06e975ebf65..a58005c3981 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -56,16 +56,6 @@
56# undef _Static_assert 56# undef _Static_assert
57#endif 57#endif
58 58
59/* If the compiler lacks __has_builtin, define it well enough for this
60 source file only. */
61#ifndef __has_builtin
62# define __has_builtin(x) _GL_HAS_##x
63# define _GL_HAS___builtin_unreachable (4 < __GNUC__ + (5 <= __GNUC_MINOR__))
64# define _GL_HAS___builtin_trap \
65 (3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))
66# define _GL_TEMPDEF___has_builtin
67#endif
68
69/* Each of these macros verifies that its argument R is nonzero. To 59/* Each of these macros verifies that its argument R is nonzero. To
70 be portable, R should be an integer constant expression. Unlike 60 be portable, R should be an integer constant expression. Unlike
71 assert (R), there is no run-time overhead. 61 assert (R), there is no run-time overhead.
@@ -243,6 +233,22 @@ template <int w>
243 233
244/* @assert.h omit start@ */ 234/* @assert.h omit start@ */
245 235
236#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
237# define _GL_HAS_BUILTIN_TRAP 1
238#elif defined __has_builtin
239# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
240#else
241# define _GL_HAS_BUILTIN_TRAP 0
242#endif
243
244#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
245# define _GL_HAS_BUILTIN_UNREACHABLE 1
246#elif defined __has_builtin
247# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
248#else
249# define _GL_HAS_BUILTIN_UNREACHABLE 0
250#endif
251
246/* Each of these macros verifies that its argument R is nonzero. To 252/* Each of these macros verifies that its argument R is nonzero. To
247 be portable, R should be an integer constant expression. Unlike 253 be portable, R should be an integer constant expression. Unlike
248 assert (R), there is no run-time overhead. 254 assert (R), there is no run-time overhead.
@@ -276,11 +282,11 @@ template <int w>
276 can suffer if R uses hard-to-optimize features such as function 282 can suffer if R uses hard-to-optimize features such as function
277 calls not inlined by the compiler. */ 283 calls not inlined by the compiler. */
278 284
279#if __has_builtin (__builtin_unreachable) 285#if _GL_HAS_BUILTIN_UNREACHABLE
280# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) 286# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
281#elif 1200 <= _MSC_VER 287#elif 1200 <= _MSC_VER
282# define assume(R) __assume (R) 288# define assume(R) __assume (R)
283#elif (defined GCC_LINT || defined lint) && __has_builtin (__builtin_trap) 289#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
284 /* Doing it this way helps various packages when configured with 290 /* Doing it this way helps various packages when configured with
285 --enable-gcc-warnings, which compiles with -Dlint. It's nicer 291 --enable-gcc-warnings, which compiles with -Dlint. It's nicer
286 when 'assume' silences warnings even with older GCCs. */ 292 when 'assume' silences warnings even with older GCCs. */
@@ -290,13 +296,6 @@ template <int w>
290# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0) 296# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
291#endif 297#endif
292 298
293#ifdef _GL_TEMPDEF___has_builtin
294# undef __has_builtin
295# undef _GL_HAS___builtin_unreachable
296# undef _GL_HAS___builtin_trap
297# undef _GL_TEMPDEF___has_builtin
298#endif
299
300/* @assert.h omit end@ */ 299/* @assert.h omit end@ */
301 300
302#endif 301#endif