]> Savannah Git Hosting - gnulib.git/commitdiff
tests: dissuade unwanted clang optimization
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 20 Nov 2024 22:55:32 +0000 (14:55 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Nov 2024 01:11:45 +0000 (17:11 -0800)
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.

22 files changed:
ChangeLog
tests/test-bsearch.c
tests/test-memccpy.c
tests/test-memchr.c
tests/test-memcmp.c
tests/test-memcpy.c
tests/test-memmove.c
tests/test-memset.c
tests/test-memset_explicit.c
tests/test-qsort.c
tests/test-strncat.c
tests/test-strncmp.c
tests/test-strncpy.c
tests/test-strndup.c
tests/test-wcsncat.c
tests/test-wcsncmp.c
tests/test-wcsncpy.c
tests/test-wmemchr.c
tests/test-wmemcmp.c
tests/test-wmemcpy.c
tests/test-wmemmove.c
tests/test-wmemset.c

index 567370aa3e2697cebb17574bc6e635249691b7f3..df1e60997c67b364c2a78352489fef452024c0ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,38 @@
 2024-11-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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.
+
        openat: omit unnecessary fd test
        * lib/openat.c (openat_permissive): Close fd regardless
        of whether it’s STDERR_FILENO.  This saves a bit of code space
index 8d62dc3e20e853cb10ff0eb36efb0dc21af4778c..28af284ed3088438190e6c93ef1f8d8657472e5b 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_bsearch (void const *key, void const *base, size_t nel, size_t width,
+             int (*compar) (void const *, void const *))
+{
+  return bsearch (key, base, nel, width, compar);
+}
+static void *(*volatile volatile_bsearch) (void const *, void const *, size_t,
+                                           size_t,
+                                           int (*) (void const *, void const *))
+  = lib_bsearch;
+#undef bsearch
+#define bsearch volatile_bsearch
+
 static int
 cmp (const void *a, const void *b)
 {
@@ -30,13 +44,9 @@ cmp (const void *a, const void *b)
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (bsearch ("x", NULL, 0, 1, cmp) == NULL);
-  ASSERT (value);
+  ASSERT (bsearch ("x", NULL, 0, 1, cmp) == NULL);
 
   return test_exit_status;
 }
index 576748dad8847096f2ab677ef1343005fb345809..b2b1c86e7c043cbee62e1336a126aa92c9262a71 100644 (file)
 
 #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)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (memccpy (NULL, "x", '?', 0) == NULL);
-  ASSERT (value);
+  ASSERT (memccpy (NULL, "x", '?', 0) == NULL);
 
   {
     char y[1];
-    value = (memccpy (y, NULL, '?', 0) == NULL);
-    ASSERT (value);
+    ASSERT (memccpy (y, NULL, '?', 0) == NULL);
   }
 
   return test_exit_status;
index ffa3a0ac2c308d98c19fde6e74b389f87852cd10..1ab0f65e3c02d63245eba6b176431827cabbda95 100644 (file)
@@ -27,6 +27,17 @@ SIGNATURE_CHECK (memchr, void *, (void const *, int, size_t));
 #include "zerosize-ptr.h"
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_memchr (void const *s, int c, size_t n)
+{
+  return memchr (s, c, n);
+}
+static void *(*volatile volatile_memchr) (void const *, int, size_t)
+  = lib_memchr;
+#undef memchr
+#define memchr volatile_memchr
+
 /* Calculating void * + int is not portable, so this wrapper converts
    to char * to make the tests easier to write.  */
 #define MEMCHR (char *) memchr
@@ -135,10 +146,7 @@ main (void)
 
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-  {
-    int volatile value = (memchr (NULL, '?', 0) == NULL);
-    ASSERT (value);
-  }
+  ASSERT (memchr (NULL, '?', 0) == NULL);
 
   return test_exit_status;
 }
index 633ba9d193176624bf1a4025eb53f37d446cdb5f..1a7e6b00cae7a84d5f128e013285ed9d6fbc129d 100644 (file)
@@ -25,11 +25,20 @@ SIGNATURE_CHECK (memcmp, int, (void const *, void const *, size_t));
 #include "zerosize-ptr.h"
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static int
+lib_memcmp (void const *s1, void const *s2, size_t n)
+{
+  return memcmp (s1, s2, n);
+}
+int (*volatile volatile_memcmp) (void const *, void const *, size_t)
+  = lib_memcmp;
+#undef memcmp
+#define memcmp volatile_memcmp
+
 int
 main (void)
 {
-  int (* volatile memcmp_ptr) (const void *, const void *, size_t) = memcmp;
-
   /* Test equal / not equal distinction.  */
   void *page_boundary1 = zerosize_ptr ();
   void *page_boundary2 = zerosize_ptr ();
@@ -50,13 +59,10 @@ main (void)
   ASSERT (memcmp ("foobar", "foo", 4) > 0);
 
   /* Some old versions of memcmp were not 8-bit clean.  */
-  /* Use the function pointer here, because otherwise this test is sometimes
-     miscompiled by 'clang'.
-     See <https://bugs.llvm.org/show_bug.cgi?id=40063>.  */
-  ASSERT (memcmp_ptr ("\100", "\201", 1) < 0);
-  ASSERT (memcmp_ptr ("\201", "\100", 1) > 0);
-  ASSERT (memcmp_ptr ("\200", "\201", 1) < 0);
-  ASSERT (memcmp_ptr ("\201", "\200", 1) > 0);
+  ASSERT (memcmp ("\100", "\201", 1) < 0);
+  ASSERT (memcmp ("\201", "\100", 1) > 0);
+  ASSERT (memcmp ("\200", "\201", 1) < 0);
+  ASSERT (memcmp ("\201", "\200", 1) > 0);
 
   /* The Next x86 OpenStep bug shows up only when comparing 16 bytes
      or more and with at least one buffer not starting on a 4-byte boundary.
@@ -75,19 +81,11 @@ main (void)
       }
   }
 
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (memcmp (NULL, "x", 0) == 0);
-  ASSERT (value);
-
-  value = (memcmp ("x", NULL, 0) == 0);
-  ASSERT (value);
-
-  value = (memcmp (NULL, NULL, 0) == 0);
-  ASSERT (value);
+  ASSERT (memcmp (NULL, "x", 0) == 0);
+  ASSERT (memcmp ("x", NULL, 0) == 0);
+  ASSERT (memcmp (NULL, NULL, 0) == 0);
 
   return test_exit_status;
 }
index a0292ea7193edd12d8d85b2c146f5609bea3b7ec..8b930cdbcb3ae544189d7c3be8b71640303114c0 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_memcpy (void *s1, void const *s2, size_t n)
+{
+  return memcpy (s1, s2, n);
+}
+void *(*volatile volatile_memcpy) (void *, void const *, size_t)
+  = lib_memcpy;
+#undef memcpy
+#define memcpy volatile_memcpy
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (memcpy (NULL, "x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (memcpy (NULL, "x", 0) == NULL);
 
   {
     char y[1];
-    value = (memcpy (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (memcpy (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index ffc24622b2d26b116d115da5f2a5c647b34b4de5..7d40c1df403840ce4ea79824829072b0f4d903f8 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_memmove (void *s1, void const *s2, size_t n)
+{
+  return memmove (s1, s2, n);
+}
+static void *(*volatile volatile_memmove) (void *, void const *, size_t)
+  = lib_memmove;
+#undef memmove
+#define memmove volatile_memmove
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (memmove (NULL, "x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (memmove (NULL, "x", 0) == NULL);
 
   {
     char y[1];
-    value = (memmove (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (memmove (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index 04fbc28fce2df094435b2797e010f7c6e7abbcf2..b15ba099dc4bfe47270118826011458f421b7c04 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_memset (void *s, int c, size_t n)
+{
+  return memset (s, c, n);
+}
+static void *(*volatile volatile_memset) (void *, int, size_t)
+  = lib_memset;
+#undef memset
+#define memset volatile_memset
+
 int
 main (void)
 {
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-  {
-    int volatile value = (memset (NULL, '?', 0) == NULL);
-    ASSERT (value);
-  }
+  ASSERT (memset (NULL, '?', 0) == NULL);
 
   return test_exit_status;
 }
index 79f2aad57070d633adae8bb7f2acb1cc9817c781..20643e1f96c4b6be907fc6fb7b61bf43c677bfad 100644 (file)
@@ -40,9 +40,21 @@ static char zero[SECRET_SIZE] = { 0 };
 
 /* Enable this to verify that the test is effective.  */
 #if 0
-# define memset_explicit(a, c, n)  memset (a, c, n)
+# undef memset_explicit
+# define memset_explicit memset
 #endif
 
+/* Test the library, not the compiler+library.  */
+static void *
+lib_memset_explicit (void *s, int c, size_t n)
+{
+  return memset_explicit (s, c, n);
+}
+static void *(*volatile volatile_memset_explicit) (void *, int, size_t)
+  = lib_memset_explicit;
+#undef memset_explicit
+#define memset_explicit volatile_memset_explicit
+
 /* Suppress GCC 13.2.1 false alarm, as this test needs a dangling pointer.  */
 #if _GL_GNUC_PREREQ (12, 0)
 # pragma GCC diagnostic ignored "-Wdangling-pointer"
@@ -135,7 +147,7 @@ test_heap (void)
 {
   char *heapbuf = (char *) malloc (SECRET_SIZE);
   ASSERT (heapbuf);
-  uintptr_t volatile addr = (uintptr_t) heapbuf;
+  uintptr_t addr = (uintptr_t) heapbuf;
   memcpy (heapbuf, SECRET, SECRET_SIZE);
   memset_explicit (heapbuf, 0, SECRET_SIZE);
   free (heapbuf);
@@ -173,8 +185,7 @@ test_stack (void)
      1. Put a secret in memory and invoke memset_explicit on it.
      2. Verify that the memory has been erased.
    Implement them in the same function, so that they access the same memory
-   range on the stack.  Declare the local scalars to be volatile so they
-   are not optimized away.  That way, the test verifies that the compiler
+   range on the stack.  That way, the test verifies that the compiler
    does not eliminate a call to memset_explicit, even if data flow analysis
    reveals that the stack area is dead at the end of the function.  */
 static bool _GL_ATTRIBUTE_NOINLINE
@@ -184,7 +195,7 @@ __attribute__ ((__noclone__))
 # if _GL_GNUC_PREREQ (8, 0)
 __attribute__ ((__noipa__))
 # endif
-do_secret_stuff (int volatile pass, char *volatile *volatile last_stackbuf)
+do_secret_stuff (int pass, char *volatile *last_stackbuf)
 {
   char stackbuf[SECRET_SIZE];
   if (pass == 1)
@@ -245,10 +256,7 @@ main ()
 
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-  {
-    int volatile value = (memset_explicit (NULL, '?', 0) == NULL);
-    ASSERT (value);
-  }
+  ASSERT (memset_explicit (NULL, '?', 0) == NULL);
 
   return test_exit_status;
 }
index 9ab39b13e4a9778b4fdb88bb7a1b869eb499825a..6083315a2fb09c76c3039da8a5e1560989ec4416 100644 (file)
 /* Specification.  */
 #include <stdlib.h>
 
+/* Test the library, not the compiler+library.  */
+static void
+lib_qsort (void *base, size_t nel, size_t width,
+           int (*compar) (void const *, void const *))
+{
+  return qsort (base, nel, width, compar);
+}
+static void (*volatile volatile_qsort) (void *, size_t, size_t,
+                                        int (*) (void const *, void const *))
+  = lib_qsort;
+#undef qsort
+#define qsort volatile_qsort
+
 static int
 cmp (const void *a, const void *b)
 {
index c7fe68227e3ee49c2c17d6179bdaf855029b77cf..c54eeeaa3465f66f86b0d8c33f01dbbaaf04781e 100644 (file)
@@ -28,6 +28,17 @@ SIGNATURE_CHECK (strncat, char *, (char *, const char *, size_t));
 #include "zerosize-ptr.h"
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static char *
+lib_strncat (char *s1, char const *s2, size_t n)
+{
+  return strncat (s1, s2, n);
+}
+static char *(*volatile volatile_strncat) (char *, char const *, size_t)
+  = lib_strncat;
+#undef strncat
+#define strncat volatile_strncat
+
 #define UNIT char
 #define U_STRNCAT strncat
 #define MAGIC ((char) 0xBA)
@@ -58,20 +69,16 @@ main ()
     check (input, SIZEOF (input));
   }
 
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
 #if 0 /* I think this is invalid, per ISO C 23 § 7.26.3.2.  */
-  value = (strncat (NULL, "x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (strncat (NULL, "x", 0) == NULL);
 #endif
 
   {
     char y[2] = { 'x', '\0' };
-    value = (strncat (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (strncat (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index 51c2be49ed36675e49b2d617a75927c9476caecd..fa2e0999b5dcb5d969d100260dc77cdc011a10d2 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static int
+lib_strncmp (char const *s1, char const *s2, size_t n)
+{
+  return strncmp (s1, s2, n);
+}
+static int (*volatile volatile_strncmp) (char const *, char const *, size_t)
+  = lib_strncmp;
+#undef strncmp
+#define strncmp volatile_strncmp
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (strncmp (NULL, "x", 0) == 0);
-  ASSERT (value);
-
-  value = (strncmp ("x", NULL, 0) == 0);
-  ASSERT (value);
-
-  value = (strncmp (NULL, NULL, 0) == 0);
-  ASSERT (value);
+  ASSERT (strncmp (NULL, "x", 0) == 0);
+  ASSERT (strncmp ("x", NULL, 0) == 0);
+  ASSERT (strncmp (NULL, NULL, 0) == 0);
 
   return test_exit_status;
 }
index 518b43d226c07529f703bc4d249983fbf01cf7ba..42bfcd539e4f99d749d1190586a6eb2a72de6ebf 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static char *
+lib_strncpy (char *s1, char const *s2, size_t n)
+{
+  return strncpy (s1, s2, n);
+}
+static char *(*volatile volatile_strncpy) (char *, char const *, size_t)
+  = lib_strncpy;
+#undef strncpy
+#define strncpy volatile_strncpy
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (strncpy (NULL, "x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (strncpy (NULL, "x", 0) == NULL);
 
   {
     char y[1];
-    value = (strncpy (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (strncpy (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index a9a1625826692861fcaf844d8358978ce9fc8992..284c7f7be40aa18debec42080479e22076a2e9e3 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static char *
+lib_strndup (char const *s, size_t size)
+{
+  return strndup (s, size);
+}
+static char *(*volatile volatile_strndup) (char const *, size_t)
+  = lib_strndup;
+#undef strndup
+#define strndup volatile_strndup
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (strndup (NULL, 0) != NULL);
-  ASSERT (value);
+  ASSERT (strndup (NULL, 0) != NULL);
 
   return test_exit_status;
 }
index 1b838261f2b19d3eb6c9853d563528c5abbd5f03..8ba20a126faa1a744b3963ad8316e9a819a412b4 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wcsncat (wchar_t *ws1, wchar_t const *ws2, size_t n)
+{
+  return wcsncat (ws1, ws2, n);
+}
+static wchar_t *(*volatile volatile_wcsncat) (wchar_t *, wchar_t const *,
+                                              size_t)
+  = lib_wcsncat;
+#undef wcsncat
+#define wcsncat volatile_wcsncat
+
 int
 main ()
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
 #if 0 /* I think this is invalid, per ISO C 23 § 7.31.4.3.2.  */
-  value = (wcsncat (NULL, L"x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (wcsncat (NULL, L"x", 0) == NULL);
 #endif
 
   {
     wchar_t y[2] = { L'x', 0 };
-    value = (wcsncat (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (wcsncat (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index c1fe103ef418bcab9d82f81c5847d949dee24468..0c6f228eeb72bbb9acd4bd0952eda4163c992c2f 100644 (file)
@@ -25,6 +25,18 @@ SIGNATURE_CHECK (wcsncmp, int, (const wchar_t *, const wchar_t *, size_t));
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static int
+lib_wcsncmp (wchar_t const *ws1, wchar_t const *ws2, size_t n)
+{
+  return wcsncmp (ws1, ws2, n);
+}
+static int (*volatile volatile_wcsncmp) (wchar_t const *,
+                                         wchar_t const *, size_t)
+  = lib_wcsncmp;
+#undef wcsncmp
+#define wcsncmp volatile_wcsncmp
+
 int
 main (int argc, char *argv[])
 {
@@ -178,19 +190,11 @@ main (int argc, char *argv[])
       }
   }
 
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (wcsncmp (NULL, L"x", 0) == 0);
-  ASSERT (value);
-
-  value = (wcsncmp (L"x", NULL, 0) == 0);
-  ASSERT (value);
-
-  value = (wcsncmp (NULL, NULL, 0) == 0);
-  ASSERT (value);
+  ASSERT (wcsncmp (NULL, L"x", 0) == 0);
+  ASSERT (wcsncmp (L"x", NULL, 0) == 0);
+  ASSERT (wcsncmp (NULL, NULL, 0) == 0);
 
   return test_exit_status;
 }
index d741a3d1ab849519ef53d90ef2b62b62f3358845..6a07bd79a67d1bded2215727274ca9fb1ebcb870 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wcsncpy (wchar_t *ws1, wchar_t const *ws2, size_t n)
+{
+  return wcsncpy (ws1, ws2, n);
+}
+static wchar_t *(*volatile volatile_wcsncpy) (wchar_t *, wchar_t const *,
+                                              size_t)
+  = lib_wcsncpy;
+#undef wcsncpy
+#define wcsncpy volatile_wcsncpy
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (wcsncpy (NULL, L"x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (wcsncpy (NULL, L"x", 0) == NULL);
 
   {
     wchar_t y[1];
-    value = (wcsncpy (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (wcsncpy (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index 3068eb983dcf7439d35ba4a2829abf2347660702..b49251e72e3b4ff3e49f3eebb8ec650b378da668 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wmemchr (wchar_t const *s, wchar_t wc, size_t n)
+{
+  return wmemchr (s, wc, n);
+}
+static wchar_t *(*volatile volatile_wmemchr) (wchar_t const *, wchar_t, size_t)
+  = lib_wmemchr;
+#undef wmemchr
+#define wmemchr volatile_wmemchr
+
 int
 main (void)
 {
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-  {
-    int volatile value = (wmemchr (NULL, L'?', 0) == NULL);
-    ASSERT (value);
-  }
+  ASSERT (wmemchr (NULL, L'?', 0) == NULL);
 
   return test_exit_status;
 }
index d7992b59ce2285175e021cc36e0ee91859822871..c29478908d2e0bf1c68e663f90973a89436f1c8b 100644 (file)
@@ -25,6 +25,17 @@ SIGNATURE_CHECK (wmemcmp, int, (const wchar_t *, const wchar_t *, size_t));
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static int
+lib_wmemcmp (wchar_t const *ws1, wchar_t const *ws2, size_t n)
+{
+  return wmemcmp (ws1, ws2, n);
+}
+int (*volatile volatile_wmemcmp) (wchar_t const *, wchar_t const *, size_t)
+  = lib_wmemcmp;
+#undef wmemcmp
+#define wmemcmp volatile_wmemcmp
+
 int
 main (int argc, char *argv[])
 {
@@ -91,19 +102,11 @@ main (int argc, char *argv[])
     ASSERT (wmemcmp (input2, input1, 1) > 0);
   }
 
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-
-  value = (wmemcmp (NULL, L"x", 0) == 0);
-  ASSERT (value);
-
-  value = (wmemcmp (L"x", NULL, 0) == 0);
-  ASSERT (value);
-
-  value = (wmemcmp (NULL, NULL, 0) == 0);
-  ASSERT (value);
+  ASSERT (wmemcmp (NULL, L"x", 0) == 0);
+  ASSERT (wmemcmp (L"x", NULL, 0) == 0);
+  ASSERT (wmemcmp (NULL, NULL, 0) == 0);
 
   return test_exit_status;
 }
index 1f67d4d5c700e210a76327dade38aaf5e032819d..ed7c2c8acbc8decbdd6ca0917295bbb1a08c323c 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wmemcpy (wchar_t *s1, wchar_t const *s2, size_t n)
+{
+  return wmemcpy (s1, s2, n);
+}
+static wchar_t *(*volatile volatile_wmemcpy) (wchar_t *, wchar_t const *,
+                                              size_t)
+  = lib_wmemcpy;
+#undef wmemcpy
+#define wmemcpy volatile_wmemcpy
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (wmemcpy (NULL, L"x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (wmemcpy (NULL, L"x", 0) == NULL);
 
   {
     wchar_t y[1];
-    value = (wmemcpy (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (wmemcpy (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index 24a73a120c7774d62d92e63eddd738b951a43ce7..d2a8d157c79af9d40b965fa0c9f0e0a3978b2707 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wmemmove (wchar_t *s1, wchar_t const *s2, size_t n)
+{
+  return wmemmove (s1, s2, n);
+}
+static wchar_t *(*volatile volatile_wmemmove) (wchar_t *, wchar_t const *,
+                                               size_t)
+  = lib_wmemmove;
+#undef wmemmove
+#define wmemmove volatile_wmemmove
+
 int
 main (void)
 {
-  int volatile value;
-
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
 
-  value = (wmemmove (NULL, L"x", 0) == NULL);
-  ASSERT (value);
+  ASSERT (wmemmove (NULL, L"x", 0) == NULL);
 
   {
     wchar_t y[1];
-    value = (wmemmove (y, NULL, 0) == y);
-    ASSERT (value);
+    ASSERT (wmemmove (y, NULL, 0) == y);
   }
 
   return test_exit_status;
index 6d7f427189c2673e154e4f30165fcea7aa0f6016..ac3de2c85c0b003388ef817985ea503703211e94 100644 (file)
 
 #include "macros.h"
 
+/* Test the library, not the compiler+library.  */
+static wchar_t *
+lib_wmemset (wchar_t *ws, wchar_t wc, size_t n)
+{
+  return wmemset (ws, wc, n);
+}
+static wchar_t *(*volatile volatile_wmemset) (wchar_t *, wchar_t, size_t)
+  = lib_wmemset;
+#undef wmemset
+#define wmemset volatile_wmemset
+
 int
 main (void)
 {
   /* Test zero-length operations on NULL pointers, allowed by
      <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf>.  */
-  {
-    int volatile value = (wmemset (NULL, L'?', 0) == NULL);
-    ASSERT (value);
-  }
+  ASSERT (wmemset (NULL, L'?', 0) == NULL);
 
   return test_exit_status;
 }