]> Savannah Git Hosting - gnulib.git/commitdiff
test-calloc-gnu: Reenable test also for GCC 7.
authorBruno Haible <bruno@clisp.org>
Sun, 5 Mar 2017 01:17:00 +0000 (02:17 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 5 Mar 2017 01:22:19 +0000 (02:22 +0100)
* tests/test-calloc-gnu.c (eight): New function.
(main): Don't skip test; use eight() instead.

ChangeLog
tests/test-calloc-gnu.c

index e856f85f448ff08272e85cbd8ec35ae65bed131f..355f5c8c0770a0dde064c8679ca4f41126283e32 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-03-04  Bruno Haible  <bruno@clisp.org>
+
+       test-calloc-gnu: Reenable test also for GCC 7.
+       * tests/test-calloc-gnu.c (eight): New function.
+       (main): Don't skip test; use eight() instead.
+
 2017-03-04  Jim Meyering  <meyering@fb.com>
 
        test-calloc-gnu: port to GCC7
index 3f964c38ed5b79c83963262d28f88f898f444c58..9dcd56d5e12daf63ba2e703848fc6236b57e77ef 100644 (file)
 
 #include <stdlib.h>
 
+/* Return 8.
+   Usual compilers are not able to infer something about the return value.  */
+static unsigned int
+eight (void)
+{
+  unsigned int x = rand ();
+  unsigned int y = x * x * x * x;
+  x++; y |= x * x * x * x;
+  x++; y |= x * x * x * x;
+  x++; y |= x * x * x * x;
+  y = y >> 1;
+  return y & -y;
+}
+
 int
 main ()
 {
@@ -27,19 +41,15 @@ main ()
     return 1;
   free (p);
 
-#if __GNUC__ < 7
-  /* GCC7's -Werror=alloc-size-larger-than= would cause the following error
-     to be detected at compile time, so skip the test for GCC7 and newer.  */
-
   /* Check that calloc fails when requested to allocate a block of memory
-     larger than SIZE_MAX bytes.  */
-  p = calloc ((size_t) -1 / 8 + 1, 8);
+     larger than SIZE_MAX bytes.
+     We use eight (), not 8, to avoid a compiler warning from GCC 7.  */
+  p = calloc ((size_t) -1 / 8 + 1, eight ());
   if (p != NULL)
     {
       free (p);
       return 1;
     }
-#endif
 
   return 0;
 }