]> Savannah Git Hosting - gnulib.git/commitdiff
jit/cache tests: Avoid test failure on hppa CPUs.
authorBruno Haible <bruno@clisp.org>
Tue, 9 Jan 2024 15:56:08 +0000 (16:56 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 18 Jan 2024 08:29:14 +0000 (09:29 +0100)
* tests/jit/test-cache.c (FUNCPTR_BIAS): New macro.
(structptr_to_funcptr, funcptr_to_structptr): New functions/macros.
(xcopy_structptr): Renamed from xcopy_funcptr. Mark as inline.
(COPY_FUNCPTR, CODE): Use structptr_to_funcptr, funcptr_to_structptr.
* modules/jit/cache-tests (configure.ac): Require AC_C_INLINE.

ChangeLog
modules/jit/cache-tests
tests/jit/test-cache.c

index aa2c6c96a8ad4f8a8dc5d79b10f64857de32242c..1c06cfe29d1a116f9652132d23d55718090a7925 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2024-01-09  Bruno Haible  <bruno@clisp.org>
+
+       jit/cache tests: Avoid test failure on hppa CPUs.
+       * tests/jit/test-cache.c (FUNCPTR_BIAS): New macro.
+       (structptr_to_funcptr, funcptr_to_structptr): New functions/macros.
+       (xcopy_structptr): Renamed from xcopy_funcptr. Mark as inline.
+       (COPY_FUNCPTR, CODE): Use structptr_to_funcptr, funcptr_to_structptr.
+       * modules/jit/cache-tests (configure.ac): Require AC_C_INLINE.
+
 2024-01-08  Bruno Haible  <bruno@clisp.org>
 
        jit/cache tests: Fix for powerpc*, ia64, hppa* CPUs.
index 2b30831f1d978884e67066fd603b72704c8b2a9c..14809b51116843bf82a5b9453a305023858bc681 100644 (file)
@@ -22,6 +22,7 @@ gl_COMPILER_OPTION_IF([-fno-ret-protector],
   [DISABLE_OPENBSD_RETGUARD='-fno-ret-protector'],
   [DISABLE_OPENBSD_RETGUARD=])
 AC_SUBST([DISABLE_OPENBSD_RETGUARD])
+AC_REQUIRE([AC_C_INLINE])
 
 Makefile.am:
 TESTS += test-cache
index 86fe4c7aecc2dc863d1ba92de97a0212b7b12bac..76c38eec9e08cba26a537c741584a9c06d9832f2 100644 (file)
@@ -82,6 +82,7 @@ struct func
   void *code_address;
   void *pic_base;
 };
+#  define FUNCPTR_BIAS 2
 # endif
 #else
 # define FUNCPTR_POINTS_TO_CODE
@@ -92,14 +93,32 @@ struct func
 # define CODE(funcptr) (funcptr)
 #else
 /* A function pointer points to a 'struct func'.  */
-static struct func *xcopy_funcptr (struct func *orig_funcptr)
+# if FUNCPTR_BIAS
+static inline void *
+structptr_to_funcptr (struct func *p)
+{
+  return (char *) p + FUNCPTR_BIAS;
+}
+static inline struct func *
+funcptr_to_structptr (void * volatile funcptr)
+{
+  return (struct func *) ((char *) funcptr - FUNCPTR_BIAS);
+}
+# else
+#  define structptr_to_funcptr(p) ((void *) (p))
+#  define funcptr_to_structptr(funcptr) ((struct func *) (funcptr))
+# endif
+static inline struct func *
+xcopy_structptr (struct func *structptr)
 {
   struct func *copy = (struct func *) xmalloc (sizeof (struct func));
-  *copy = *orig_funcptr;
+  *copy = *structptr;
   return copy;
 }
-# define COPY_FUNCPTR(funcptr) (void *) xcopy_funcptr ((struct func *)(funcptr))
-# define CODE(funcptr) (((struct func *)(funcptr))->code_address)
+# define COPY_FUNCPTR(funcptr) \
+    structptr_to_funcptr (xcopy_structptr (funcptr_to_structptr (funcptr)))
+# define CODE(funcptr) \
+    ((funcptr_to_structptr (funcptr))->code_address)
 #endif
 
 /* This test assumes that the code generated by the compiler for the