]> Savannah Git Hosting - gnulib.git/commitdiff
intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.
authorBruno Haible <bruno@clisp.org>
Fri, 18 Dec 2020 12:10:27 +0000 (13:10 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 18 Dec 2020 12:10:27 +0000 (13:10 +0100)
Reported by Stefan Liebler <stli@linux.ibm.com> in
<https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>.

* lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for
GCC 5.x and 6.x.
* lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for
GCC 5.x and 6.x.

ChangeLog
lib/glob.c
lib/intprops.h

index 2c6fae91032f4e15b95b61b3e1e02461fd47edaa..ae62fd779295d3a9f1afe48f0cab02aade4d22a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-12-18  Bruno Haible  <bruno@clisp.org>
+
+       intprops: Avoid potentially buggy __builtin_add_overflow in GCC 5, 6.
+       Reported by Stefan Liebler <stli@linux.ibm.com> in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2020-12/msg00152.html>.
+       * lib/intprops.h (_GL_HAS_BUILTIN_ADD_OVERFLOW): Don't define for
+       GCC 5.x and 6.x.
+       * lib/glob.c (size_add_wrapv): Don't use __builtin_add_overflow for
+       GCC 5.x and 6.x.
+
 2020-12-17  Bruno Haible  <bruno@clisp.org>
 
        free: Fix warning.
index 32e2e115ab9ee164451c38d72c1b93c085fb9dea..3c444d3b1395cbfe568773c7a0bb59a12edbb374 100644 (file)
@@ -227,7 +227,7 @@ glob_lstat (glob_t *pglob, int flags, const char *fullname)
 static bool
 size_add_wrapv (size_t a, size_t b, size_t *r)
 {
-#if 5 <= __GNUC__ && !defined __ICC
+#if 7 <= __GNUC__ && !defined __ICC
   return __builtin_add_overflow (a, b, r);
 #else
   *r = a + b;
index 8cc8138f90c203a7b3905465cb45824ebcfb7158..2472962e6761d3c4f1c41c9684e9e128475851d7 100644 (file)
 
 /* True if __builtin_add_overflow (A, B, P) and __builtin_sub_overflow
    (A, B, P) work when P is non-null.  */
-#if 5 <= __GNUC__ && !defined __ICC
+/* __builtin_{add,sub}_overflow exists but is not reliable in GCC 5.x and 6.x,
+   see <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98269>.  */
+#if 7 <= __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)