+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
{
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++)
#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++)
static void
do_allocation (int n)
{
- void *ptr = alloca (n);
+ void *volatile ptr = alloca (n);
(void) ptr;
}
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);
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;
}
static void
do_allocation (int n)
{
- void *ptr = malloca (n);
+ void *volatile ptr = malloca (n);
freea (ptr);
safe_alloca (n);
}
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;
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;
}
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. */