Hash :
15efa15b
Author :
Date :
2024-11-20T14:55:32
tests: dissuade unwanted clang optimization Pacify Apple clang 14.0.0 (clang-1400.0.29.202) for arm64-apple-darwin21.6.0 on test-memset_explicit.c, which otherwise complains “warning: null passed to a callee that requires a non-null argument [-Wnonnull]” and presumably could do an unwanted optimization based on this analysis. Do other tests consistently. * tests/test-bsearch.c (lib_bsearch, volatile_bsearch, bsearch): * tests/test-memccpy.c (lib_memccpy, volatile_memccpy, memccpy): * tests/test-memchr.c (lib_memchr, volatile_memchr, memchr): * tests/test-memcmp.c (lib_memcmp, volatile_memcmp, memcmp): * tests/test-memcpy.c (lib_memcpy, volatile_memcpy, memcpy): * tests/test-memmove.c (lib_memmove, volatile_memmove, memmove): * tests/test-memset.c (lib_memset, volatile_memset, memset): * tests/test-memset_explicit.c (lib_memset_explicit) (volatile_memset_explicit, memset_explicit): * tests/test-qsort.c (lib_qsort, volatile_qsort, qsort): * tests/test-strncat.c (lib_strncat, volatile_strncat, strncat): * tests/test-strncmp.c (lib_strncmp, volatile_strncmp, strncmp): * tests/test-strncpy.c (lib_strncpy, volatile_strncpy, strncpy): * tests/test-strndup.c (lib_strndup, volatile_strndup, strndup): * tests/test-wcsncat.c (lib_wcsncat, volatile_wcsncat, wcsncat): * tests/test-wcsncmp.c (lib_wcsncmp, volatile_wcsncmp, wcsncmp): * tests/test-wcsncpy.c (lib_wcsncpy, volatile_wcsncpy, wcsncpy): * tests/test-wmemchr.c (lib_wmemchr, volatile_wmemchr, wmemchr): * tests/test-wmemcmp.c (lib_wmemcmp, volatile_wmemcmp, wmemcmp): * tests/test-wmemcpy.c (lib_wmemcpy, volatile_wmemcpy, wmemcpy): * tests/test-wmemmove.c (lib_wmemmove, volatile_wmemmove, wmemmove): * tests/test-wmemset.c (lib_wmemset, volatile_wmemset, wmemset) Convince the compiler to not optimize based on what it thinks about the function. Callers changed to not use volatile locals, since they should no longer be needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/* Test of memccpy() function.
Copyright (C) 2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <string.h>
#include <stddef.h>
#include "macros.h"
/* Test the library, not the compiler+library. */
static void *
lib_memccpy (void *dest, void const *src, int c, size_t n)
{
return memccpy (dest, src, c, n);
}
static void *(*volatile volatile_memccpy) (void *, void const *, int, size_t)
= lib_memccpy;
#undef memccpy
#define memccpy volatile_memccpy
int
main (void)
{
/* Test zero-length operations on NULL pointers, allowed by
<https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>. */
ASSERT (memccpy (NULL, "x", '?', 0) == NULL);
{
char y[1];
ASSERT (memccpy (y, NULL, '?', 0) == NULL);
}
return test_exit_status;
}