This patch fixes a test failure on Linux/hppa and NetBSD/hppa. The cause of the failure was that on 32-bit hppa platforms, a function pointer is not merely a 'struct func *', but a 'struct func *' + 2.
2024-01-09 Bruno Haible <br...@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. diff --git a/modules/jit/cache-tests b/modules/jit/cache-tests index 2b30831f1d..14809b5111 100644 --- a/modules/jit/cache-tests +++ b/modules/jit/cache-tests @@ -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 diff --git a/tests/jit/test-cache.c b/tests/jit/test-cache.c index 86fe4c7aec..76c38eec9e 100644 --- a/tests/jit/test-cache.c +++ b/tests/jit/test-cache.c @@ -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