]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
Revisit some -Wuseless-cast changes.
authorBruno Haible <bruno@clisp.org>
Sun, 10 May 2026 22:10:44 +0000 (00:10 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 10 May 2026 22:10:44 +0000 (00:10 +0200)
* lib/fstrcmp.c (fstrcmp_free_resources, fstrcmp_bounded): Use a
compound literal to convert to uintptr_t.
* lib/wait-process.c (wait_subprocess): Use a compound literal to
convert to int.
* lib/sigsegv.c: Revert last change. Instead, disable -Wuseless-cast
in this compilation unit.
* tests/jit/test-cache.c: Likewise.
* tests/test-limits-h.c: Disable -Wuseless-cast warnings also for
gcc 14, 15.

ChangeLog
lib/fstrcmp.c
lib/sigsegv.c
lib/wait-process.c
tests/jit/test-cache.c
tests/test-limits-h.c

index d0f2d1af5f76331d573de1d524876083e95a1f1e..34b78ecc4e2000a208dd0299f0136793a15d344f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2026-05-10  Bruno Haible  <bruno@clisp.org>
+
+       Revisit some -Wuseless-cast changes.
+       * lib/fstrcmp.c (fstrcmp_free_resources, fstrcmp_bounded): Use a
+       compound literal to convert to uintptr_t.
+       * lib/wait-process.c (wait_subprocess): Use a compound literal to
+       convert to int.
+       * lib/sigsegv.c: Revert last change. Instead, disable -Wuseless-cast
+       in this compilation unit.
+       * tests/jit/test-cache.c: Likewise.
+       * tests/test-limits-h.c: Disable -Wuseless-cast warnings also for
+       gcc 14, 15.
+
 2026-05-10  Bruno Haible  <bruno@clisp.org>
 
        Fix many test failures on Windows and 32-bit AIX (regr. 2026-05-08).
index 69aca5d0e7c63a4133a0cd967d67dd5c7a579c00..5a1c2733943b59216a155f3fcd46c8ca66530bdc 100644 (file)
@@ -82,7 +82,7 @@ fstrcmp_free_resources (void)
   if (buffer != NULL)
     {
       gl_tls_set (buffer_key, NULL);
-      gl_tls_set (bufmax_key, (void *) (uintptr_t) 0);
+      gl_tls_set (bufmax_key, (void *) (uintptr_t) {0});
       free (buffer);
     }
 }
@@ -214,7 +214,7 @@ fstrcmp_bounded (const char *string1, const char *string2, double lower_bound)
       free (buffer);
       buffer = xnmalloc (bufmax, 2 * sizeof *buffer);
       gl_tls_set (buffer_key, buffer);
-      gl_tls_set (bufmax_key, (void *) bufmax);
+      gl_tls_set (bufmax_key, (void *) (uintptr_t) {bufmax});
     }
   ctxt.fdiag = buffer + yvec_length + 1;
   ctxt.bdiag = ctxt.fdiag + fdiag_len;
index cdedbf849d542668d9b27113bfa73fa4ca2f9b8a..ccd23bd5ba08f21c97accac9339ecab3ac559970 100644 (file)
 # include <sys/param.h> /* defines macro OpenBSD */
 #endif
 
+/* The value of SIGSEGV_FAULT_ADDRESS may be any representation of an address
+   (void *, char *, uintptr_t, intptr_t), depending on platform.  The cast is
+   therefore mandatory, to avoid a compilation error or warning.  */
+#if _GL_GNUC_PREREQ (14, 0)
+# pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif
+
 
 /* Version number.  */
 int libsigsegv_version = LIBSIGSEGV_VERSION;
@@ -362,7 +369,7 @@ int libsigsegv_version = LIBSIGSEGV_VERSION;
 #if defined __gnu_hurd__ /* Hurd */
 
 # define SIGSEGV_FAULT_HANDLER_ARGLIST  int sig, long code, struct sigcontext *scp
-# define SIGSEGV_FAULT_ADDRESS  (void *) (unsigned long) code
+# define SIGSEGV_FAULT_ADDRESS  (unsigned long) code
 # define SIGSEGV_FAULT_CONTEXT  scp
 
 # if defined __x86_64__
@@ -1017,7 +1024,7 @@ static sigsegv_handler_t user_handler = (sigsegv_handler_t)NULL;
 static void
 sigsegv_handler (SIGSEGV_FAULT_HANDLER_ARGLIST)
 {
-  void *address = SIGSEGV_FAULT_ADDRESS;
+  void *address = (void *) (SIGSEGV_FAULT_ADDRESS);
 
 # if HAVE_STACK_OVERFLOW_RECOVERY
 #  if !(HAVE_STACKVMA || defined SIGSEGV_FAULT_STACKPOINTER)
@@ -1260,7 +1267,7 @@ install_for (int sig)
   struct sigaction action;
 
 # ifdef SIGSEGV_FAULT_ADDRESS_FROM_SIGINFO
-  action.sa_sigaction = sigsegv_handler;
+  action.sa_sigaction = (void (*) (int, siginfo_t *, void *)) &sigsegv_handler;
 # else
   action.sa_handler = (void (*) (int)) &sigsegv_handler;
 # endif
index 2e3cf70a11a30b1036ff0ff1e0b4b04fe02d25e7..f8ce59a4c927b5f3e28e90302afb8571aebdbae1 100644 (file)
@@ -383,7 +383,7 @@ wait_subprocess (pid_t child, const char *progname,
       if (exit_on_error || (!null_stderr && termsigp == NULL))
         error (exit_on_error ? EXIT_FAILURE : 0, 0,
                _("%s subprocess got fatal signal %d"),
-               progname, WTERMSIG (status));
+               progname, (int) {WTERMSIG (status)});
       return 127;
     }
   if (!WIFEXITED (status))
index 8bf152f4ed948f72429632f5637085e443d943a1..292287bd243ccedca1c31a902e6f51bae27f65eb 100644 (file)
 #endif
 static int clang_ubsan_workaround = 0;
 
+/* This file freely casts between the different representations of addresses
+   (void *, char *, function pointers, uintptr_t).  Not worth warning about.  */
+#if _GL_GNUC_PREREQ (14, 0)
+# pragma GCC diagnostic ignored "-Wuseless-cast"
+#endif
+
 /* On most platforms, function pointers are just a pointer to the
    code, i.e. to the first instruction to be executed.  This,
    however, is not universally true, see:
@@ -116,7 +122,7 @@ struct func
 # else
 #  define CODE(funcptr) ((char *) (funcptr) - clang_ubsan_workaround)
 #  define SET_CODE(funcptr,code_addr) \
-     ((void) ((funcptr) = (void *) ((code_addr) + clang_ubsan_workaround)))
+     ((void) ((funcptr) = (void *) ((char *) (code_addr) + clang_ubsan_workaround)))
 #  define IS(funcptr) ((void) (funcptr), 0)
 #  define SET_IS(funcptr,is) ((void) (funcptr), (void) (is))
 # endif
index 5688a3e2d33c5cce7d709f4959cb2146f1a9ce14..8691caa32e1ee042cd09d68ab5c321d8a5a5a669 100644 (file)
@@ -27,8 +27,8 @@
 #define verify_width(width, min, max) \
   static_assert ((max) >> ((width) - 1 - ((min) < 0)) == 1)
 
-/* Macros borrowed from intprops.h.  */
-#if 16 <= __GNUC__
+/* Macros borrowed from intprops.h and intprops-internal.h.  */
+#if 14 <= __GNUC__
 # pragma GCC diagnostic ignored "-Wuseless-cast"
 #endif
 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))