]> git.eshelyaron.com Git - emacs.git/commitdiff
Don’t ignore -Wclobbered in emacs-module.c
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Aug 2024 23:59:08 +0000 (16:59 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 20 Aug 2024 14:08:50 +0000 (16:08 +0200)
This fix is also prompted by Emacs bug#71744.
* src/emacs-module.c: Do not ignore -Wclobbered.
(MODULE_HANDLE_NONLOCAL_EXIT): Fix violations of the C standard,
where setjmp clobbered env and internal_cleanup.
(module_extract_big_integer) [GCC_LINT && __GNUC__ && !__clang__]:
Work around GCC -Wclobbered false positive for ‘sign’.

(cherry picked from commit cfa5a634e91f5c232a71ec212679165074dc480b)

src/emacs-module.c

index 05aa0baef74df64d6ba6efb36dd23a41ecbb52d7..5aa4cfa0ae85242fe0eec360555f9d0cc8f7139c 100644 (file)
@@ -96,11 +96,6 @@ To add a new module function, proceed as follows:
 #include <intprops.h>
 #include <verify.h>
 
-/* Work around GCC bug 83162.  */
-#if GNUC_PREREQ (4, 3, 0)
-# pragma GCC diagnostic ignored "-Wclobbered"
-#endif
-
 /* We use different strategies for allocating the user-visible objects
    (struct emacs_runtime, emacs_env, emacs_value), depending on
    whether the user supplied the -module-assertions flag.  If
@@ -273,14 +268,17 @@ module_decode_utf_8 (const char *str, ptrdiff_t len)
       module_out_of_memory (env);                                      \
       return retval;                                                   \
     }                                                                  \
-  struct handler *internal_cleanup                                      \
+  emacs_env *env_volatile = env;                                       \
+  struct handler *volatile internal_cleanup                            \
     = internal_handler;                                                 \
-  if (sys_setjmp (internal_cleanup->jmp))                               \
+  if (sys_setjmp (internal_handler->jmp))                              \
     {                                                                  \
+      emacs_env *env = env_volatile;                                   \
+      struct handler *internal_handler = internal_cleanup;     \
       module_handle_nonlocal_exit (env,                                 \
-                                   internal_cleanup->nonlocal_exit,     \
-                                   internal_cleanup->val);              \
-      module_reset_handlerlist (internal_cleanup);                     \
+                                  internal_handler->nonlocal_exit,     \
+                                  internal_handler->val);              \
+      module_reset_handlerlist (internal_handler);                     \
       return retval;                                                   \
     }                                                                  \
   do { } while (false)
@@ -1045,6 +1043,15 @@ static bool
 module_extract_big_integer (emacs_env *env, emacs_value arg, int *sign,
                             ptrdiff_t *count, emacs_limb_t *magnitude)
 {
+#if GCC_LINT && __GNUC__ && !__clang__
+  /* These useless assignments pacify GCC 14.2.1 x86-64
+     <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21161>.  */
+  {
+    int *volatile sign_volatile = sign;
+    sign = sign_volatile;
+  }
+#endif
+
   MODULE_FUNCTION_BEGIN (false);
   Lisp_Object o = value_to_lisp (arg);
   CHECK_INTEGER (o);