diffutils-3.5-gcc7.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. Cumulative Backports from upstream to address gcc 7 portablility issues
  2. Imported from Fedora
  3. Upstream-Status: Backport
  4. Signed-off-by: Khem Raj <raj.khem@gmail.com>
  5. diff -up diffutils-3.5/lib/intprops.h.than diffutils-3.5/lib/intprops.h
  6. --- diffutils-3.5/lib/intprops.h.than 2017-02-21 09:08:39.470417367 -0500
  7. +++ diffutils-3.5/lib/intprops.h 2017-02-21 09:46:57.090996508 -0500
  8. @@ -1,6 +1,6 @@
  9. /* intprops.h -- properties of integer types
  10. - Copyright (C) 2001-2016 Free Software Foundation, Inc.
  11. + Copyright (C) 2001-2017 Free Software Foundation, Inc.
  12. This program is free software: you can redistribute it and/or modify it
  13. under the terms of the GNU General Public License as published
  14. @@ -47,12 +47,16 @@
  15. /* Minimum and maximum values for integer types and expressions. */
  16. +/* The width in bits of the integer type or expression T.
  17. + Padding bits are not supported; this is checked at compile-time below. */
  18. +#define TYPE_WIDTH(t) (sizeof (t) * CHAR_BIT)
  19. +
  20. /* The maximum and minimum values for the integer type T. */
  21. #define TYPE_MINIMUM(t) ((t) ~ TYPE_MAXIMUM (t))
  22. #define TYPE_MAXIMUM(t) \
  23. ((t) (! TYPE_SIGNED (t) \
  24. ? (t) -1 \
  25. - : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
  26. + : ((((t) 1 << (TYPE_WIDTH (t) - 2)) - 1) * 2 + 1)))
  27. /* The maximum and minimum values for the type of the expression E,
  28. after integer promotion. E should not have side effects. */
  29. @@ -65,7 +69,13 @@
  30. ? _GL_SIGNED_INT_MAXIMUM (e) \
  31. : _GL_INT_NEGATE_CONVERT (e, 1))
  32. #define _GL_SIGNED_INT_MAXIMUM(e) \
  33. - (((_GL_INT_CONVERT (e, 1) << (sizeof ((e) + 0) * CHAR_BIT - 2)) - 1) * 2 + 1)
  34. + (((_GL_INT_CONVERT (e, 1) << (TYPE_WIDTH ((e) + 0) - 2)) - 1) * 2 + 1)
  35. +
  36. +/* Work around OpenVMS incompatibility with C99. */
  37. +#if !defined LLONG_MAX && defined __INT64_MAX
  38. +# define LLONG_MAX __INT64_MAX
  39. +# define LLONG_MIN __INT64_MIN
  40. +#endif
  41. /* This include file assumes that signed types are two's complement without
  42. padding bits; the above macros have undefined behavior otherwise.
  43. @@ -84,10 +94,15 @@ verify (TYPE_MAXIMUM (long int) == LONG_
  44. verify (TYPE_MINIMUM (long long int) == LLONG_MIN);
  45. verify (TYPE_MAXIMUM (long long int) == LLONG_MAX);
  46. #endif
  47. +/* Similarly, sanity-check one ISO/IEC TS 18661-1:2014 macro if defined. */
  48. +#ifdef UINT_WIDTH
  49. +verify (TYPE_WIDTH (unsigned int) == UINT_WIDTH);
  50. +#endif
  51. /* Does the __typeof__ keyword work? This could be done by
  52. 'configure', but for now it's easier to do it by hand. */
  53. -#if (2 <= __GNUC__ || defined __IBM__TYPEOF__ \
  54. +#if (2 <= __GNUC__ \
  55. + || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \
  56. || (0x5110 <= __SUNPRO_C && !__STDC__))
  57. # define _GL_HAVE___TYPEOF__ 1
  58. #else
  59. @@ -116,8 +131,7 @@ verify (TYPE_MAXIMUM (long long int) ==
  60. signed, this macro may overestimate the true bound by one byte when
  61. applied to unsigned types of size 2, 4, 16, ... bytes. */
  62. #define INT_STRLEN_BOUND(t) \
  63. - (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \
  64. - - _GL_SIGNED_TYPE_OR_EXPR (t)) \
  65. + (INT_BITS_STRLEN_BOUND (TYPE_WIDTH (t) - _GL_SIGNED_TYPE_OR_EXPR (t)) \
  66. + _GL_SIGNED_TYPE_OR_EXPR (t))
  67. /* Bound on buffer size needed to represent an integer type or expression T,
  68. @@ -222,20 +236,23 @@ verify (TYPE_MAXIMUM (long long int) ==
  69. ? (a) < (min) >> (b) \
  70. : (max) >> (b) < (a))
  71. -/* True if __builtin_add_overflow (A, B, P) works when P is null. */
  72. -#define _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL (7 <= __GNUC__)
  73. +/* True if __builtin_add_overflow (A, B, P) works when P is non-null. */
  74. +#define _GL_HAS_BUILTIN_OVERFLOW (5 <= __GNUC__)
  75. +
  76. +/* True if __builtin_add_overflow_p (A, B, C) works. */
  77. +#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
  78. /* The _GL*_OVERFLOW macros have the same restrictions as the
  79. *_RANGE_OVERFLOW macros, except that they do not assume that operands
  80. (e.g., A and B) have the same type as MIN and MAX. Instead, they assume
  81. that the result (e.g., A + B) has that type. */
  82. -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
  83. -# define _GL_ADD_OVERFLOW(a, b, min, max)
  84. - __builtin_add_overflow (a, b, (__typeof__ ((a) + (b)) *) 0)
  85. -# define _GL_SUBTRACT_OVERFLOW(a, b, min, max)
  86. - __builtin_sub_overflow (a, b, (__typeof__ ((a) - (b)) *) 0)
  87. -# define _GL_MULTIPLY_OVERFLOW(a, b, min, max)
  88. - __builtin_mul_overflow (a, b, (__typeof__ ((a) * (b)) *) 0)
  89. +#if _GL_HAS_BUILTIN_OVERFLOW_P
  90. +# define _GL_ADD_OVERFLOW(a, b, min, max) \
  91. + __builtin_add_overflow_p (a, b, (__typeof__ ((a) + (b))) 0)
  92. +# define _GL_SUBTRACT_OVERFLOW(a, b, min, max) \
  93. + __builtin_sub_overflow_p (a, b, (__typeof__ ((a) - (b))) 0)
  94. +# define _GL_MULTIPLY_OVERFLOW(a, b, min, max) \
  95. + __builtin_mul_overflow_p (a, b, (__typeof__ ((a) * (b))) 0)
  96. #else
  97. # define _GL_ADD_OVERFLOW(a, b, min, max) \
  98. ((min) < 0 ? INT_ADD_RANGE_OVERFLOW (a, b, min, max) \
  99. @@ -315,7 +332,7 @@ verify (TYPE_MAXIMUM (long long int) ==
  100. _GL_BINARY_OP_OVERFLOW (a, b, _GL_ADD_OVERFLOW)
  101. #define INT_SUBTRACT_OVERFLOW(a, b) \
  102. _GL_BINARY_OP_OVERFLOW (a, b, _GL_SUBTRACT_OVERFLOW)
  103. -#if _GL_HAS_BUILTIN_OVERFLOW_WITH_NULL
  104. +#if _GL_HAS_BUILTIN_OVERFLOW_P
  105. # define INT_NEGATE_OVERFLOW(a) INT_SUBTRACT_OVERFLOW (0, a)
  106. #else
  107. # define INT_NEGATE_OVERFLOW(a) \
  108. @@ -349,10 +366,6 @@ verify (TYPE_MAXIMUM (long long int) ==
  109. #define INT_MULTIPLY_WRAPV(a, b, r) \
  110. _GL_INT_OP_WRAPV (a, b, r, *, __builtin_mul_overflow, INT_MULTIPLY_OVERFLOW)
  111. -#ifndef __has_builtin
  112. -# define __has_builtin(x) 0
  113. -#endif
  114. -
  115. /* Nonzero if this compiler has GCC bug 68193 or Clang bug 25390. See:
  116. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68193
  117. https://llvm.org/bugs/show_bug.cgi?id=25390
  118. @@ -369,7 +382,7 @@ verify (TYPE_MAXIMUM (long long int) ==
  119. the operation. BUILTIN is the builtin operation, and OVERFLOW the
  120. overflow predicate. Return 1 if the result overflows. See above
  121. for restrictions. */
  122. -#if 5 <= __GNUC__ || __has_builtin (__builtin_add_overflow)
  123. +#if _GL_HAS_BUILTIN_OVERFLOW
  124. # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) builtin (a, b, r)
  125. #elif 201112 <= __STDC_VERSION__ && !_GL__GENERIC_BOGUS
  126. # define _GL_INT_OP_WRAPV(a, b, r, op, builtin, overflow) \
  127. @@ -412,7 +425,7 @@ verify (TYPE_MAXIMUM (long long int) ==
  128. # else
  129. # define _GL_INT_OP_WRAPV_LONGISH(a, b, r, op, overflow) \
  130. _GL_INT_OP_CALC (a, b, r, op, overflow, unsigned long int, \
  131. - long int, LONG_MIN, LONG_MAX))
  132. + long int, LONG_MIN, LONG_MAX)
  133. # endif
  134. #endif
  135. diff -up diffutils-3.5/lib/xalloc-oversized.h.than diffutils-3.5/lib/xalloc-oversized.h
  136. --- diffutils-3.5/lib/xalloc-oversized.h.than 2017-02-21 09:45:13.729168233 -0500
  137. +++ diffutils-3.5/lib/xalloc-oversized.h 2017-02-21 09:45:18.309249247 -0500
  138. @@ -1,6 +1,6 @@
  139. /* xalloc-oversized.h -- memory allocation size checking
  140. - Copyright (C) 1990-2000, 2003-2004, 2006-2016 Free Software Foundation, Inc.
  141. + Copyright (C) 1990-2000, 2003-2004, 2006-2017 Free Software Foundation, Inc.
  142. This program is free software: you can redistribute it and/or modify
  143. it under the terms of the GNU General Public License as published by
  144. @@ -19,48 +19,37 @@
  145. #define XALLOC_OVERSIZED_H_
  146. #include <stddef.h>
  147. +#include <stdint.h>
  148. -/* Default for (non-Clang) compilers that lack __has_builtin. */
  149. -#ifndef __has_builtin
  150. -# define __has_builtin(x) 0
  151. -#endif
  152. -
  153. -/* True if N * S would overflow in a size calculation.
  154. +/* True if N * S would overflow in a size_t calculation,
  155. + or would generate a value larger than PTRDIFF_MAX.
  156. This expands to a constant expression if N and S are both constants.
  157. By gnulib convention, SIZE_MAX represents overflow in size
  158. - calculations, so the conservative dividend to use here is
  159. - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value.
  160. - However, malloc (SIZE_MAX) fails on all known hosts where
  161. - sizeof (ptrdiff_t) <= sizeof (size_t), so do not bother to test for
  162. - exactly-SIZE_MAX allocations on such hosts; this avoids a test and
  163. - branch when S is known to be 1. */
  164. + calculations, so the conservative size_t-based dividend to use here
  165. + is SIZE_MAX - 1. */
  166. #define __xalloc_oversized(n, s) \
  167. - ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
  168. + ((size_t) (PTRDIFF_MAX < SIZE_MAX ? PTRDIFF_MAX : SIZE_MAX - 1) / (s) < (n))
  169. +#if PTRDIFF_MAX < SIZE_MAX
  170. +typedef ptrdiff_t __xalloc_count_type;
  171. +#else
  172. +typedef size_t __xalloc_count_type;
  173. +#endif
  174. -/* Return 1 if an array of N objects, each of size S, cannot exist due
  175. - to size arithmetic overflow. S must be positive and N must be
  176. - nonnegative. This is a macro, not a function, so that it
  177. - works correctly even when SIZE_MAX < N. */
  178. +/* Return 1 if an array of N objects, each of size S, cannot exist
  179. + reliably due to size or ptrdiff_t arithmetic overflow. S must be
  180. + positive and N must be nonnegative. This is a macro, not a
  181. + function, so that it works correctly even when SIZE_MAX < N. */
  182. -/* GCC 7 __builtin_mul_overflow should easily compute this. See:
  183. - https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68120 */
  184. #if 7 <= __GNUC__
  185. -# define xalloc_oversized(n, s) __builtin_mul_overflow (n, s, (size_t *) NULL)
  186. -
  187. -/* GCC 5 and Clang __builtin_mul_overflow needs a temporary, and
  188. - should be used only for non-constant operands, so that
  189. - xalloc_oversized is a constant expression if both arguments are.
  190. - Do not use this if pedantic, since pedantic GCC issues a diagnostic
  191. - for ({ ... }). */
  192. -#elif ((5 <= __GNUC__ \
  193. - || (__has_builtin (__builtin_mul_overflow) \
  194. - && __has_builtin (__builtin_constant_p))) \
  195. - && !__STRICT_ANSI__)
  196. +# define xalloc_oversized(n, s) \
  197. + __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
  198. +#elif 5 <= __GNUC__ && !__STRICT_ANSI__
  199. # define xalloc_oversized(n, s) \
  200. (__builtin_constant_p (n) && __builtin_constant_p (s) \
  201. ? __xalloc_oversized (n, s) \
  202. - : ({ size_t __xalloc_size; __builtin_mul_overflow (n, s, &__xalloc_size); }))
  203. + : ({ __xalloc_count_type __xalloc_count; \
  204. + __builtin_mul_overflow (n, s, &__xalloc_count); }))
  205. /* Other compilers use integer division; this may be slower but is
  206. more portable. */