From 2169a9387a5ac22b969d37ece4ec1aaa0fd830d9 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 16 Aug 2024 16:29:51 -0700 Subject: [PATCH 1/6] =?UTF-8?q?Don=E2=80=99t=20ignore=20-Wclobbered=20in?= =?UTF-8?q?=20bytecode.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/bytecode.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) 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 @@ #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 @@ #define DEFINE(name, value) [name] = &&insn_ ## name, 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 @@ #define DEFINE(name, value) [name] = &&insn_ ## name, goto op_branch; } + saved_quitcounter = quitcounter; +#if GCC_LINT && __GNUC__ && !__clang__ + saved_vectorp = vectorp; + saved_bytestr_data = bytestr_data; +#endif NEXT; } -- 2.43.0