summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2021-04-20 17:11:51 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2021-04-20 17:12:51 -0700
commit591f00666450e5e70514d457846af2c8d301af9b (patch)
tree9e1eca1a9d5840831f5235f315e71f552437f0d6 /tests
parent9b8db75dbe7c33d5dc7eccee84f80c17c18223c1 (diff)
downloadgnulib-591f00666450e5e70514d457846af2c8d301af9b.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-aligned-malloc.c8
-rw-r--r--tests/test-aligned_alloc.c12
-rw-r--r--tests/test-alloca-opt.c2
-rw-r--r--tests/test-malloc-gnu.c5
-rw-r--r--tests/test-malloca.c2
-rw-r--r--tests/test-realloc-gnu.c5
-rw-r--r--tests/test-reallocarray.c3
7 files changed, 20 insertions, 17 deletions
diff --git a/tests/test-aligned-malloc.c b/tests/test-aligned-malloc.c
index 0a1b4d7106..92f34bca3f 100644
--- a/tests/test-aligned-malloc.c
+++ b/tests/test-aligned-malloc.c
@@ -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++)
diff --git a/tests/test-aligned_alloc.c b/tests/test-aligned_alloc.c
index 123c251233..9aba4c8ba9 100644
--- a/tests/test-aligned_alloc.c
+++ b/tests/test-aligned_alloc.c
@@ -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++)
diff --git a/tests/test-alloca-opt.c b/tests/test-alloca-opt.c
index edca8e65f6..fdbf6f5881 100644
--- a/tests/test-alloca-opt.c
+++ b/tests/test-alloca-opt.c
@@ -25,7 +25,7 @@
static void
do_allocation (int n)
{
- void *ptr = alloca (n);
+ void *volatile ptr = alloca (n);
(void) ptr;
}
diff --git a/tests/test-malloc-gnu.c b/tests/test-malloc-gnu.c
index e1dfde452c..d8e7b04a8f 100644
--- a/tests/test-malloc-gnu.c
+++ b/tests/test-malloc-gnu.c
@@ -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;
}
diff --git a/tests/test-malloca.c b/tests/test-malloca.c
index deb813c5ac..52d95a5d97 100644
--- a/tests/test-malloca.c
+++ b/tests/test-malloca.c
@@ -25,7 +25,7 @@
static void
do_allocation (int n)
{
- void *ptr = malloca (n);
+ void *volatile ptr = malloca (n);
freea (ptr);
safe_alloca (n);
}
diff --git a/tests/test-realloc-gnu.c b/tests/test-realloc-gnu.c
index b62ee6badc..f4c00c0bf7 100644
--- a/tests/test-realloc-gnu.c
+++ b/tests/test-realloc-gnu.c
@@ -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;
}
diff --git a/tests/test-reallocarray.c b/tests/test-reallocarray.c
index a6e0cbbfd2..9c4a189efc 100644
--- a/tests/test-reallocarray.c
+++ b/tests/test-reallocarray.c
@@ -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. */