From: Pip Cet <pipcet@protonmail.com>
To: Andrea Corallo <acorallo@gnu.org>
Cc: emacs-devel@gnu.org, Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: master 8c81818673a 6/7: Tune volatile in read_char
Date: Sat, 17 Aug 2024 17:03:26 +0000 [thread overview]
Message-ID: <87zfpbgjz7.fsf@protonmail.com> (raw)
In-Reply-To: <yp1wmkffax9.fsf@fencepost.gnu.org>
"Andrea Corallo" <acorallo@gnu.org> writes:
> Paul Eggert <eggert@cs.ucla.edu> writes:
>
>> branch: master
>> commit 8c81818673ae9ff788c6e65fb90984f327b27964
>> Author: Paul Eggert <eggert@cs.ucla.edu>
>> Commit: Paul Eggert <eggert@cs.ucla.edu>
>>
>> Tune volatile in read_char
>>
>> * src/keyboard.c (read_char): Optimize access to a local volatile.
>
> Hi Paul,
>
> this change building with "--enable-checking=all
> --enable-check-lisp-object-type" on my system (GCC 14
> x86_64-pc-linux-gnu) is introducing:
>
> "keyboard.c:2520:15: warning: variable ‘c’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]"
Well, GCC is late to the party, we already found that bug ;-)
I think GCC, by its own logic, is right about this one. It doesn't know
that local_getcjmp is local (and hasn't escaped), so it would be, in
theory, possible for a signal handler to call 'longjmp' before
c_volatile is initialized. And since GCC does not distinguish between
the two branches following a 'setjmp', it might end up using the value
of 'c' which might hypothetically have been clobbered.
Of course there are many reasons that can't actually happen, but the GCC
limitations are well known and we can work around them:
diff --git a/src/keyboard.c b/src/keyboard.c
index 0d3506bc59b..0992fab653b 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -2752,7 +2752,7 @@ read_char (int commandflag, Lisp_Object map,
it *must not* be in effect when we call redisplay. */
specpdl_ref jmpcount = SPECPDL_INDEX ();
- Lisp_Object volatile c_volatile;
+ Lisp_Object volatile c_volatile = c;
if (sys_setjmp (local_getcjmp))
{
c = c_volatile;
@@ -2800,7 +2800,6 @@ read_char (int commandflag, Lisp_Object map,
goto non_reread;
}
- c_volatile = c;
#if GCC_LINT && __GNUC__ && !__clang__
/* This useless assignment pacifies GCC 14.2.1 x86-64
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21161>. */
Does that help? It does here, but these warnings are highly dependent on
the precise GCC version and optimization flags used, which is why I
still think we should default to -Werror=clobbered to catch distributors
performing LTO builds and such.
Pip
next prev parent reply other threads:[~2024-08-17 17:03 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <172386820621.30556.15409337288904485218@vcs2.savannah.gnu.org>
[not found] ` <20240817041648.A6687C2BC66@vcs2.savannah.gnu.org>
2024-08-17 15:04 ` master 8c81818673a 6/7: Tune volatile in read_char Andrea Corallo
2024-08-17 17:03 ` Pip Cet [this message]
2024-08-17 18:16 ` Paul Eggert
2024-08-17 18:17 ` Paul Eggert
2024-08-18 7:39 ` Andrea Corallo
2024-08-18 21:39 ` Paul Eggert
2024-08-18 21:57 ` Sam James
2024-08-18 22:03 ` Paul Eggert
2024-08-19 14:43 ` Andrea Corallo
2024-08-19 15:01 ` Eli Zaretskii
2024-08-19 15:32 ` Pip Cet
2024-08-19 15:44 ` Eli Zaretskii
2024-08-19 16:01 ` Pip Cet
2024-08-19 16:15 ` Eli Zaretskii
2024-08-19 18:59 ` Paul Eggert
2024-08-19 19:27 ` Eli Zaretskii
2024-08-19 19:05 ` Pip Cet
2024-08-19 19:29 ` Eli Zaretskii
2024-08-19 19:43 ` Paul Eggert
2024-08-19 20:08 ` Pip Cet
2024-08-19 22:20 ` Paul Eggert
2024-08-19 23:40 ` Pip Cet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zfpbgjz7.fsf@protonmail.com \
--to=pipcet@protonmail.com \
--cc=acorallo@gnu.org \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.