+2019-10-23 Paul Eggert <eggert@cs.ucla.edu>
+
+ Port better to GCC under macOS
+ 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.
+
2019-10-22 Akim Demaille <akim@lrde.epita.fr>
maintainer-makefile: update rule for argmatch.
#include <limits.h>
-/* If the compiler lacks __has_builtin, define it well enough for this
- source file only. */
-#ifndef __has_builtin
-# define __has_builtin(x) _GL_HAS_##x
-# if 5 <= __GNUC__ && !defined __ICC
-# define _GL_HAS___builtin_add_overflow 1
-# else
-# define _GL_HAS___builtin_add_overflow 0
-# endif
-# define _GL_TEMPDEF___has_builtin
-#endif
-
/* Return a value with the common real type of E and V and the value of V.
Do not evaluate E. */
#define _GL_INT_CONVERT(e, v) ((1 ? 0 : (e)) + (v))
/* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
(A, B, P) work when P is non-null. */
-#if __has_builtin (__builtin_add_overflow)
+#if 5 <= __GNUC__ && !defined __ICC
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 1
+#elif defined __has_builtin
+# define _GL_HAS_BUILTIN_ADD_OVERFLOW __has_builtin (__builtin_add_overflow)
#else
# define _GL_HAS_BUILTIN_ADD_OVERFLOW 0
#endif
: (tmin) / (a) < (b)) \
: (tmax) / (b) < (a)))
-#ifdef _GL_TEMPDEF___has_builtin
-# undef __has_builtin
-# undef _GL_HAS___builtin_add_overflow
-# undef _GL_TEMPDEF___has_builtin
-#endif
-
#endif /* _GL_INTPROPS_H */
# undef _Static_assert
#endif
-/* If the compiler lacks __has_builtin, define it well enough for this
- source file only. */
-#ifndef __has_builtin
-# define __has_builtin(x) _GL_HAS_##x
-# define _GL_HAS___builtin_unreachable (4 < __GNUC__ + (5 <= __GNUC_MINOR__))
-# define _GL_HAS___builtin_trap \
- (3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)))
-# define _GL_TEMPDEF___has_builtin
-#endif
-
/* Each of these macros verifies that its argument R is nonzero. To
be portable, R should be an integer constant expression. Unlike
assert (R), there is no run-time overhead.
/* @assert.h omit start@ */
+#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
+# define _GL_HAS_BUILTIN_TRAP 1
+#elif defined __has_builtin
+# define _GL_HAS_BUILTIN_TRAP __has_builtin (__builtin_trap)
+#else
+# define _GL_HAS_BUILTIN_TRAP 0
+#endif
+
+#if 4 < __GNUC__ + (5 <= __GNUC_MINOR__)
+# define _GL_HAS_BUILTIN_UNREACHABLE 1
+#elif defined __has_builtin
+# define _GL_HAS_BUILTIN_UNREACHABLE __has_builtin (__builtin_unreachable)
+#else
+# define _GL_HAS_BUILTIN_UNREACHABLE 0
+#endif
+
/* Each of these macros verifies that its argument R is nonzero. To
be portable, R should be an integer constant expression. Unlike
assert (R), there is no run-time overhead.
can suffer if R uses hard-to-optimize features such as function
calls not inlined by the compiler. */
-#if __has_builtin (__builtin_unreachable)
+#if _GL_HAS_BUILTIN_UNREACHABLE
# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
#elif 1200 <= _MSC_VER
# define assume(R) __assume (R)
-#elif (defined GCC_LINT || defined lint) && __has_builtin (__builtin_trap)
+#elif (defined GCC_LINT || defined lint) && _GL_HAS_BUILTIN_TRAP
/* Doing it this way helps various packages when configured with
--enable-gcc-warnings, which compiles with -Dlint. It's nicer
when 'assume' silences warnings even with older GCCs. */
# define assume(R) ((R) ? (void) 0 : /*NOTREACHED*/ (void) 0)
#endif
-#ifdef _GL_TEMPDEF___has_builtin
-# undef __has_builtin
-# undef _GL_HAS___builtin_unreachable
-# undef _GL_HAS___builtin_trap
-# undef _GL_TEMPDEF___has_builtin
-#endif
-
/* @assert.h omit end@ */
#endif