From: Bruno Haible <bruno@clisp.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: bug-gnulib@gnu.org
Subject: Re: [PATCH 1/2] explicit_bzero-tests: pacify GCC
Date: Mon, 19 Jul 2021 00:23:04 +0200 [thread overview]
Message-ID: <2568272.mkVSEl9qYJ@omega> (raw)
In-Reply-To: <3ecc5494-65ab-cb9e-19c7-8aaef7b6ff18@cs.ucla.edu>
Paul Eggert wrote:
> I take your point that the patch changes the meaning of the test in an
> undesirable way. I installed the attached to implement your suggestion.
Thank you.
> This new diagnostic points out a problem with the test, though. If GCC
> can determine that memcmp reads uninitialized storage, GCC can optimize
> away the memcmp and act as if memcmp returns 0 (or any other constant).
> So the test as it stands is problematic given recent advances in
> practical compilers.
Such compiler optimizations would need to be backed by the standards.
Are there initiatives to "outlaw" references to uninitialized storage
in recent C or C++ standards?
I hope code such as
int x; /* uninitialized */
if (!((x & 1) == 0 || (x & 1) == 1))
abort ();
will never crash. x & 1 can only be 0 or 1. Tertium not datur.
Also, I think the danger is small: GCC does not _know_ that the array
is uninitialized. It's only a "maybe uninitialized". If GCC ever
infers that it is "certainly uninitialized", we could defeat that
through a use of 'volatile', such as
int (* volatile memcmp_func) (const void *, const void *, size_t) = memcmp;
> As an aside, I don't understand the discussion of asynchronous signal
> invocations in that test's commentary. There is no asynchronous
> signaling in that code.
In some operating systems, interrupt handling uses the stack of the
currently executing thread. While this is not the case in Linux [1],
it was definitely the case in Atari TOS, and is still probably the
case in some embedded OSes for MMU-less CPUs.
Bruno
[1] https://stackoverflow.com/questions/28759227/which-stack-is-used-by-interrupt-handler-linux
next prev parent reply other threads:[~2021-07-18 22:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-18 4:56 [PATCH 1/2] explicit_bzero-tests: pacify GCC Paul Eggert
2021-07-18 4:56 ` [PATCH 2/2] memrchr-tests: " Paul Eggert
2021-07-18 9:12 ` [PATCH 1/2] explicit_bzero-tests: " Bruno Haible
2021-07-18 19:14 ` Paul Eggert
2021-07-18 22:23 ` Bruno Haible [this message]
2021-07-18 23:17 ` Paul Eggert
2021-07-19 0:37 ` Bruno Haible
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
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2568272.mkVSEl9qYJ@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
--cc=eggert@cs.ucla.edu \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).