From: Paul Eggert Date: Fri, 16 Aug 2024 23:29:51 +0000 (-0700) Subject: Don’t ignore -Wclobbered in bytecode.c X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=652df068006675be0330b236f9cff27c7e16f08f;p=emacs.git Don’t ignore -Wclobbered in bytecode.c This fix is prompted by Emacs bug#71744. The working hypothesis is that there are some bugs in Emacs, and some in GCC’s diagnostics, and that this patch fixes the Emacs bugs and works around the GCC diagnostic bugs. The hypothesis is that GCC diagnostic bugs occur when GCC coalesces variables or temporaries and some variables are clobbered by setjmp and some vars/temps are not. Part of this hypothesis involves GCC diagnosing the wrong variables. Instead of ignoring the diagnostics, which the hypothesis suggests indicate either problems in Emacs or in GCC, fix the Emacs bugs and pacify the GCC false positives, with comments about the GCC bugs. GCC’s true positives are helpful enough in squashing obscure bugs like Emacs bug#71744, that it’s worth going to some effort to pacify -Wclobbered instead of ignoring it. * src/bytecode.c: Do not ignore -Wclobbered. (exec_byte_code): Fix violations of the C standard, where setjmp clobbered quitcounter and bc. If GCC_LINT && __GNUC__ && !__clang__, work around GCC -Wclobbered warnings for bytestr_data and vectorp. (cherry picked from commit 2169a9387a5ac22b969d37ece4ec1aaa0fd830d9) --- diff --git a/src/bytecode.c b/src/bytecode.c index ce075c86afd..48a29c22d55 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -29,11 +29,6 @@ along with GNU Emacs. If not, see . */ #include "window.h" #include "puresize.h" -/* Work around GCC bug 54561. */ -#if GNUC_PREREQ (4, 3, 0) -# pragma GCC diagnostic ignored "-Wclobbered" -#endif - /* Define BYTE_CODE_SAFE true to enable some minor sanity checking, useful for debugging the byte compiler. It defaults to false. */ @@ -536,6 +531,12 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, for (ptrdiff_t i = nargs - rest; i < nonrest; i++) PUSH (Qnil); + unsigned char volatile saved_quitcounter; +#if GCC_LINT && __GNUC__ && !__clang__ + Lisp_Object *volatile saved_vectorp; + unsigned char const *volatile saved_bytestr_data; +#endif + while (true) { int op; @@ -967,15 +968,23 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, if (sys_setjmp (c->jmp)) { + quitcounter = saved_quitcounter; struct handler *c = handlerlist; handlerlist = c->next; top = c->bytecode_top; op = c->bytecode_dest; + bc = ¤t_thread->bc; struct bc_frame *fp = bc->fp; Lisp_Object fun = fp->fun; Lisp_Object bytestr = AREF (fun, CLOSURE_CODE); Lisp_Object vector = AREF (fun, CLOSURE_CONSTANTS); +#if GCC_LINT && __GNUC__ && !__clang__ + /* These useless assignments pacify GCC 14.2.1 x86-64 + . */ + bytestr_data = saved_bytestr_data; + vectorp = saved_vectorp; +#endif bytestr_data = SDATA (bytestr); vectorp = XVECTOR (vector)->contents; if (BYTE_CODE_SAFE) @@ -989,6 +998,11 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, goto op_branch; } + saved_quitcounter = quitcounter; +#if GCC_LINT && __GNUC__ && !__clang__ + saved_vectorp = vectorp; + saved_bytestr_data = bytestr_data; +#endif NEXT; }