On Mon, Aug 29, 2016 at 3:58 PM, Jim Meyering <j...@meyering.net> wrote:
> On Mon, Aug 29, 2016 at 12:05 PM, Paul Eggert <egg...@cs.ucla.edu> wrote:
>> Jim Meyering wrote:
>>
>>> Good catch.
>>> Thanks.
>>
>>
>> In trying it out on GNU Emacs with GCC 6.2 I ran into another problem: it
>> complains at compile-time if __builtin_add_overflow's 3rd arg is null. In
>> some GCC versions this is supposed to discard the value, but I guess that
>> capability is superseded by __builtin_add_overflow_p. So I installed the
>> attached additional patch, which avoids the need for a null argument so we
>> don't have to worry about GCC version details there.
>
> Thanks for making that work with 6.2
> I noticed that you did not update the use in lib/xalloc-oversized.h,
> and that too fails to compile with gcc-6.2.

I've just pushed this to fix it:
From bb26f2c4cd826e8b20863354a3a79af95785f3b0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Mon, 29 Aug 2016 16:33:43 -0700
Subject: [PATCH] xalloc-oversized.h: port __builtin_mul_overflow change to GCC
 6.2.0

* lib/xalloc-oversized.h: Port this change to GCC 6.2.0, too,
similarly to how it was done to intprops.h.
---
 ChangeLog              |  6 ++++++
 lib/xalloc-oversized.h | 13 +------------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cc437f5..d694076 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2016-08-29  Jim Meyering  <meyer...@fb.com>
+
+       xalloc-oversized.h: port __builtin_mul_overflow change to GCC 6.2.0
+       * lib/xalloc-oversized.h: Port this change to GCC 6.2.0, too,
+       similarly to how it was done to intprops.h.
+
 2016-08-29  Paul Eggert  <egg...@cs.ucla.edu>

        intprops.h: port recent changes to GCC 6.2.0
diff --git a/lib/xalloc-oversized.h b/lib/xalloc-oversized.h
index 9954f50..53e6556 100644
--- a/lib/xalloc-oversized.h
+++ b/lib/xalloc-oversized.h
@@ -43,19 +43,8 @@
    nonnegative.  This is a macro, not a function, so that it
    works correctly even when SIZE_MAX < N.  */

-#if 7 <= __GNUC__
+#if 7 <= __GNUC__ || __has_builtin (__builtin_add_overflow_p)
 # define xalloc_oversized(n, s) __builtin_mul_overflow_p (n, s, (size_t) 1)
-
-/* GCC 6 __builtin_mul_overflow should easily compute this.  See:
-   https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68120  */
-#elif 6 == __GNUC__
-# define xalloc_oversized(n, s) __builtin_mul_overflow (n, s, (size_t *) NULL)
-
-/* GCC 5 and Clang __builtin_mul_overflow needs a temporary, and
-   should be used only for non-constant operands, so that
-   xalloc_oversized is a constant expression if both arguments are.
-   Do not use this if pedantic, since pedantic GCC issues a diagnostic
-   for ({ ... }).  */
 #elif ((5 <= __GNUC__ \
         || (__has_builtin (__builtin_mul_overflow) \
             && __has_builtin (__builtin_constant_p))) \
--
2.8.0.rc2

Reply via email to