bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: dissuade unwanted clang optimization


From: Paul Eggert
Subject: [PATCH] tests: dissuade unwanted clang optimization
Date: Wed, 20 Nov 2024 17:12:06 -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.
---
 ChangeLog                    | 33 +++++++++++++++++++++++++++++++
 tests/test-bsearch.c         | 20 ++++++++++++++-----
 tests/test-memccpy.c         | 19 ++++++++++++------
 tests/test-memchr.c          | 16 +++++++++++----
 tests/test-memcmp.c          | 38 +++++++++++++++++-------------------
 tests/test-memcpy.c          | 19 ++++++++++++------
 tests/test-memmove.c         | 19 ++++++++++++------
 tests/test-memset.c          | 16 +++++++++++----
 tests/test-memset_explicit.c | 26 +++++++++++++++---------
 tests/test-qsort.c           | 13 ++++++++++++
 tests/test-strncat.c         | 19 ++++++++++++------
 tests/test-strncmp.c         | 25 +++++++++++++-----------
 tests/test-strncpy.c         | 19 ++++++++++++------
 tests/test-strndup.c         | 17 +++++++++++-----
 tests/test-wcsncat.c         | 20 +++++++++++++------
 tests/test-wcsncmp.c         | 26 +++++++++++++-----------
 tests/test-wcsncpy.c         | 20 +++++++++++++------
 tests/test-wmemchr.c         | 16 +++++++++++----
 tests/test-wmemcmp.c         | 25 +++++++++++++-----------
 tests/test-wmemcpy.c         | 20 +++++++++++++------
 tests/test-wmemmove.c        | 20 +++++++++++++------
 tests/test-wmemset.c         | 16 +++++++++++----
 22 files changed, 320 insertions(+), 142 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 567370aa3e..df1e60997c 100644
--- 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
diff --git a/tests/test-bsearch.c b/tests/test-bsearch.c
index 8d62dc3e20..28af284ed3 100644
--- a/tests/test-bsearch.c
+++ b/tests/test-bsearch.c
@@ -21,6 +21,20 @@
 
 #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;
 }
diff --git a/tests/test-memccpy.c b/tests/test-memccpy.c
index 576748dad8..b2b1c86e7c 100644
--- a/tests/test-memccpy.c
+++ b/tests/test-memccpy.c
@@ -23,21 +23,28 @@
 
 #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;
diff --git a/tests/test-memchr.c b/tests/test-memchr.c
index ffa3a0ac2c..1ab0f65e3c 100644
--- a/tests/test-memchr.c
+++ b/tests/test-memchr.c
@@ -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;
 }
diff --git a/tests/test-memcmp.c b/tests/test-memcmp.c
index 633ba9d193..1a7e6b00ca 100644
--- a/tests/test-memcmp.c
+++ b/tests/test-memcmp.c
@@ -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;
 }
diff --git a/tests/test-memcpy.c b/tests/test-memcpy.c
index a0292ea719..8b930cdbcb 100644
--- a/tests/test-memcpy.c
+++ b/tests/test-memcpy.c
@@ -23,21 +23,28 @@
 
 #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;
diff --git a/tests/test-memmove.c b/tests/test-memmove.c
index ffc24622b2..7d40c1df40 100644
--- a/tests/test-memmove.c
+++ b/tests/test-memmove.c
@@ -23,21 +23,28 @@
 
 #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;
diff --git a/tests/test-memset.c b/tests/test-memset.c
index 04fbc28fce..b15ba099dc 100644
--- a/tests/test-memset.c
+++ b/tests/test-memset.c
@@ -23,15 +23,23 @@
 
 #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;
 }
diff --git a/tests/test-memset_explicit.c b/tests/test-memset_explicit.c
index 79f2aad570..20643e1f96 100644
--- a/tests/test-memset_explicit.c
+++ b/tests/test-memset_explicit.c
@@ -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;
 }
diff --git a/tests/test-qsort.c b/tests/test-qsort.c
index 9ab39b13e4..6083315a2f 100644
--- a/tests/test-qsort.c
+++ b/tests/test-qsort.c
@@ -19,6 +19,19 @@
 /* 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)
 {
diff --git a/tests/test-strncat.c b/tests/test-strncat.c
index c7fe68227e..c54eeeaa34 100644
--- a/tests/test-strncat.c
+++ b/tests/test-strncat.c
@@ -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;
diff --git a/tests/test-strncmp.c b/tests/test-strncmp.c
index 51c2be49ed..fa2e0999b5 100644
--- a/tests/test-strncmp.c
+++ b/tests/test-strncmp.c
@@ -23,22 +23,25 @@
 
 #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;
 }
diff --git a/tests/test-strncpy.c b/tests/test-strncpy.c
index 518b43d226..42bfcd539e 100644
--- a/tests/test-strncpy.c
+++ b/tests/test-strncpy.c
@@ -23,21 +23,28 @@
 
 #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;
diff --git a/tests/test-strndup.c b/tests/test-strndup.c
index a9a1625826..284c7f7be4 100644
--- a/tests/test-strndup.c
+++ b/tests/test-strndup.c
@@ -23,16 +23,23 @@
 
 #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;
 }
diff --git a/tests/test-wcsncat.c b/tests/test-wcsncat.c
index 1b838261f2..8ba20a126f 100644
--- a/tests/test-wcsncat.c
+++ b/tests/test-wcsncat.c
@@ -25,23 +25,31 @@
 
 #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;
diff --git a/tests/test-wcsncmp.c b/tests/test-wcsncmp.c
index c1fe103ef4..0c6f228eeb 100644
--- a/tests/test-wcsncmp.c
+++ b/tests/test-wcsncmp.c
@@ -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;
 }
diff --git a/tests/test-wcsncpy.c b/tests/test-wcsncpy.c
index d741a3d1ab..6a07bd79a6 100644
--- a/tests/test-wcsncpy.c
+++ b/tests/test-wcsncpy.c
@@ -23,21 +23,29 @@
 
 #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;
diff --git a/tests/test-wmemchr.c b/tests/test-wmemchr.c
index 3068eb983d..b49251e72e 100644
--- a/tests/test-wmemchr.c
+++ b/tests/test-wmemchr.c
@@ -23,15 +23,23 @@
 
 #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;
 }
diff --git a/tests/test-wmemcmp.c b/tests/test-wmemcmp.c
index d7992b59ce..c29478908d 100644
--- a/tests/test-wmemcmp.c
+++ b/tests/test-wmemcmp.c
@@ -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;
 }
diff --git a/tests/test-wmemcpy.c b/tests/test-wmemcpy.c
index 1f67d4d5c7..ed7c2c8acb 100644
--- a/tests/test-wmemcpy.c
+++ b/tests/test-wmemcpy.c
@@ -23,21 +23,29 @@
 
 #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;
diff --git a/tests/test-wmemmove.c b/tests/test-wmemmove.c
index 24a73a120c..d2a8d157c7 100644
--- a/tests/test-wmemmove.c
+++ b/tests/test-wmemmove.c
@@ -23,21 +23,29 @@
 
 #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;
diff --git a/tests/test-wmemset.c b/tests/test-wmemset.c
index 6d7f427189..ac3de2c85c 100644
--- a/tests/test-wmemset.c
+++ b/tests/test-wmemset.c
@@ -23,15 +23,23 @@
 
 #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;
 }
-- 
2.47.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]