]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
malloc-gnu-tests, etc.: use volatile for clang
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Apr 2021 00:11:51 +0000 (17:11 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Apr 2021 00:12:51 +0000 (17:12 -0700)
In some more test locations, store the result of malloc etc. into
a volatile pointer so that clang doesn’t optimize away the malloc
and thus bypass the test.  This fixes a malloc-gnu test failure on
macOS 11.2.3 with clang 12.0.0 on ARM.
* tests/test-alloca-opt.c (do_allocation):
* tests/test-malloc-gnu.c (main):
* tests/test-malloca.c (do_allocation):
* tests/test-realloc-gnu.c (main):
* tests/test-reallocarray.c (main):
* tests/test-aligned-malloc.c (main):
* tests/test-aligned_alloc.c (main):
Store malloc etc. results into a volatile pointer.

ChangeLog
tests/test-aligned-malloc.c
tests/test-aligned_alloc.c
tests/test-alloca-opt.c
tests/test-malloc-gnu.c
tests/test-malloca.c
tests/test-realloc-gnu.c
tests/test-reallocarray.c

index 0146e159442427daf0cc81f9b0d94857dcb5dda6..d2ea4e5093cd05c818257d7069883588f9198ce8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2021-04-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+       malloc-gnu-tests, etc.: use volatile for clang
+       In some more test locations, store the result of malloc etc. into
+       a volatile pointer so that clang doesn’t optimize away the malloc
+       and thus bypass the test.  This fixes a malloc-gnu test failure on
+       macOS 11.2.3 with clang 12.0.0 on ARM.
+       * tests/test-alloca-opt.c (do_allocation):
+       * tests/test-malloc-gnu.c (main):
+       * tests/test-malloca.c (do_allocation):
+       * tests/test-realloc-gnu.c (main):
+       * tests/test-reallocarray.c (main):
+       * tests/test-aligned-malloc.c (main):
+       * tests/test-aligned_alloc.c (main):
+       Store malloc etc. results into a volatile pointer.
+
 2021-04-18  Paul Eggert  <eggert@cs.ucla.edu>
 
        malloc-gnu-tests: pacify -Walloc-size-larger-than
index 0a1b4d710658108c00721461d5e6ffd233ce9a84..92f34bca3f1124a937ce110693fbcf16e29c198f 100644 (file)
@@ -63,10 +63,10 @@ main (int argc, char *argv[])
 {
   static size_t sizes[] =
     { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641 };
-  void *aligned4_blocks[SIZEOF (sizes)];
-  void *aligned8_blocks[SIZEOF (sizes)];
-  void *aligned16_blocks[SIZEOF (sizes)];
-  void *aligned32_blocks[SIZEOF (sizes)];
+  void *volatile aligned4_blocks[SIZEOF (sizes)];
+  void *volatile aligned8_blocks[SIZEOF (sizes)];
+  void *volatile aligned16_blocks[SIZEOF (sizes)];
+  void *volatile aligned32_blocks[SIZEOF (sizes)];
   size_t i;
 
   for (i = 0; i < SIZEOF (sizes); i++)
index 123c251233d434fb3adc2ada576074e56bd6ffab..9aba4c8ba9b25fd1a4e17a3cd40b621c974ff665 100644 (file)
@@ -36,12 +36,12 @@ main (int argc, char *argv[])
 #if HAVE_ALIGNED_ALLOC
   static size_t sizes[] =
     { 13, 8, 17, 450, 320, 1, 99, 4, 15, 16, 2, 76, 37, 127, 2406, 641, 5781 };
-  void *aligned2_blocks[SIZEOF (sizes)];
-  void *aligned4_blocks[SIZEOF (sizes)];
-  void *aligned8_blocks[SIZEOF (sizes)];
-  void *aligned16_blocks[SIZEOF (sizes)];
-  void *aligned32_blocks[SIZEOF (sizes)];
-  void *aligned64_blocks[SIZEOF (sizes)];
+  void *volatile aligned2_blocks[SIZEOF (sizes)];
+  void *volatile aligned4_blocks[SIZEOF (sizes)];
+  void *volatile aligned8_blocks[SIZEOF (sizes)];
+  void *volatile aligned16_blocks[SIZEOF (sizes)];
+  void *volatile aligned32_blocks[SIZEOF (sizes)];
+  void *volatile aligned64_blocks[SIZEOF (sizes)];
   size_t i;
 
   for (i = 0; i < SIZEOF (sizes); i++)
index edca8e65f6e142a262900dddd755a198ba84b96c..fdbf6f5881c6a61805b74c0c460639e71576cdd2 100644 (file)
@@ -25,7 +25,7 @@
 static void
 do_allocation (int n)
 {
-  void *ptr = alloca (n);
+  void *volatile ptr = alloca (n);
   (void) ptr;
 }
 
index e1dfde452c3d13466112d4b2ed9b08148844ed29..d8e7b04a8f0ec4f2d2febd21fa7b180a8674e1ac 100644 (file)
@@ -23,7 +23,7 @@ int
 main (int argc, char **argv)
 {
   /* Check that malloc (0) is not a NULL pointer.  */
-  char *p = malloc (0);
+  void *volatile p = malloc (0);
   if (p == NULL)
     return 1;
   free (p);
@@ -32,7 +32,8 @@ main (int argc, char **argv)
   if (PTRDIFF_MAX < SIZE_MAX)
     {
       size_t one = argc != 12345;
-      if (malloc (PTRDIFF_MAX + one) != NULL)
+      p = malloc (PTRDIFF_MAX + one);
+      if (p != NULL)
         return 1;
     }
 
index deb813c5ac004edf332344d9e2fdf5052325b205..52d95a5d9761a4eea797810e500de7775f018ab6 100644 (file)
@@ -25,7 +25,7 @@
 static void
 do_allocation (int n)
 {
-  void *ptr = malloca (n);
+  void *volatile ptr = malloca (n);
   freea (ptr);
   safe_alloca (n);
 }
index b62ee6badc4f5c13e3f603d4b2ce8d277c76bd42..f4c00c0bf7b3b17d24b2598715ba3cacccfa9eb9 100644 (file)
@@ -23,7 +23,7 @@ int
 main (int argc, char **argv)
 {
   /* Check that realloc (NULL, 0) is not a NULL pointer.  */
-  char *p = realloc (NULL, 0);
+  void *volatile p = realloc (NULL, 0);
   if (p == NULL)
     return 1;
 
@@ -32,7 +32,8 @@ main (int argc, char **argv)
   if (PTRDIFF_MAX < SIZE_MAX)
     {
       size_t one = argc != 12345;
-      if (realloc (p, PTRDIFF_MAX + one) != NULL)
+      p = realloc (p, PTRDIFF_MAX + one);
+      if (p != NULL)
         return 1;
     }
 
index a6e0cbbfd2704459f779018769442cbbdad48381..9c4a189efc24e4dfe75cc1fdf27dccaea9cb2a23 100644 (file)
@@ -31,7 +31,8 @@ main ()
       of memory larger than SIZE_MAX bytes.  */
    for (n = 2; n != 0; n <<= 1)
      {
-       if (reallocarray (NULL, (size_t) -1 / n + 1, n))
+       void *volatile p = reallocarray (NULL, (size_t) -1 / n + 1, n);
+       if (p)
          return 1;
 
        /* Ensure that errno is correctly set.  */