]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
memcmp tests: Work around the clang bug.
authorBruno Haible <bruno@clisp.org>
Sat, 21 Dec 2019 04:42:11 +0000 (05:42 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 21 Dec 2019 04:42:11 +0000 (05:42 +0100)
* tests/test-memcmp.c (main): Use a volatile function pointer to disable
the clang optimization.

ChangeLog
tests/test-memcmp.c

index 9a47dbc18bf6e595d815f52b3ad32af4b1353926..ee50002459cacce065f7289dfc4b137f6d646a99 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-12-21  Bruno Haible  <bruno@clisp.org>
+
+       memcmp tests: Work around the clang bug.
+       * tests/test-memcmp.c (main): Use a volatile function pointer to disable
+       the clang optimization.
+
 2019-12-20  Bruno Haible  <bruno@clisp.org>
 
        localcharset: Add support for z/OS encoding names.
index 5d481194ec03026b7182ac510cb3486f25a70a41..f0bddef702d60cb315206ce9461995feecf24d69 100644 (file)
@@ -25,12 +25,11 @@ SIGNATURE_CHECK (memcmp, int, (void const *, void const *, size_t));
 #include "zerosize-ptr.h"
 #include "macros.h"
 
-/* Note: This test sometimes fails when compiled by 'clang'.
-   See <https://bugs.llvm.org/show_bug.cgi?id=40063>.  */
-
 int
 main (void)
 {
+  int (* volatile memcmp_ptr) (const void *, const void *, size_t) = memcmp;
+
   /* Test equal / not equal distinction.  */
   ASSERT (memcmp (zerosize_ptr (), zerosize_ptr (), 0) == 0);
   ASSERT (memcmp ("foo", "foobar", 2) == 0);
@@ -48,10 +47,13 @@ main (void)
   ASSERT (memcmp ("foobar", "foo", 4) > 0);
 
   /* Some old versions of memcmp were not 8-bit clean.  */
-  ASSERT (memcmp ("\100", "\201", 1) < 0);
-  ASSERT (memcmp ("\201", "\100", 1) > 0);
-  ASSERT (memcmp ("\200", "\201", 1) < 0);
-  ASSERT (memcmp ("\201", "\200", 1) > 0);
+  /* 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);
 
   /* 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.