]> Savannah Git Hosting - gnulib.git/commitdiff
intprops, xalloc: avoid __builtin_mul_overflow_p with Clang
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 17 Sep 2020 19:17:15 +0000 (12:17 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 17 Sep 2020 19:17:37 +0000 (12:17 -0700)
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.

ChangeLog
lib/intprops.h
lib/xalloc-oversized.h

index b484c8dec4ffe4910b65bc454d1f9158c9703464..a3a8ab1e22c164c23301be19e83a031af846e336 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2020-09-17  Paul Eggert  <eggert@cs.ucla.edu>
 
+       intprops, xalloc: avoid __builtin_mul_overflow_p with Clang
+       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.
+
        libc-config: port __THROW to Ubuntu 4
        * lib/cdefs.h (__THROW): Do not use __attribute__ ((__nothrow__))
        for GCC 3.3.  Problem reported by Jeffrey Walton in:
index df66a3877abbe9e563e2b285297e2702c8106adc..cb086715bcb418ff4043e3822f6c6a86720063d6 100644 (file)
 
 /* True if __builtin_add_overflow_p (A, B, C) works, and similarly for
    __builtin_sub_overflow_p and __builtin_mul_overflow_p.  */
-#define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
+#ifdef __clang__
+/* Clang 9 lacks __builtin_mul_overflow_p, and even if it did it would
+   presumably run afoul of Clang bug 16404.  */
+# define _GL_HAS_BUILTIN_OVERFLOW_P 0
+#else
+# define _GL_HAS_BUILTIN_OVERFLOW_P (7 <= __GNUC__)
+#endif
 
 /* The _GL*_OVERFLOW macros have the same restrictions as the
    *_RANGE_OVERFLOW macros, except that they do not assume that operands
index 13ee23031a0535b8086e8f006086d64ed14546f5..7cd4a74f04d2f1f550a6d6d60b1d0c245374b4d4 100644 (file)
@@ -41,7 +41,7 @@ typedef size_t __xalloc_count_type;
    positive and N must be nonnegative.  This is a macro, not a
    function, so that it works correctly even when SIZE_MAX < N.  */
 
-#if 7 <= __GNUC__
+#if 7 <= __GNUC__ && !defined __clang__
 # define xalloc_oversized(n, s) \
    __builtin_mul_overflow_p (n, s, (__xalloc_count_type) 1)
 #elif 5 <= __GNUC__ && !defined __ICC && !__STRICT_ANSI__