public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "vajdaz at protonmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/93934] Unnecessary fld of uninitialized float stack variable results in ub of valid C++ code
Date: Wed, 13 Oct 2021 17:54:28 +0000	[thread overview]
Message-ID: <bug-93934-4-AZWudek7Zq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-93934-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93934

--- Comment #15 from Zoltan Vajda <vajdaz at protonmail dot com> ---
In my special case, I have an embedded realtime application with a lot of FP
atithmetic on Intel 32 bit architecture (huge and complex legacy codebase). FPU
exceptions are enabled, so loading an SNaN results in an exception. This is
intended, and we will don't want to change this configuration. In this context
the generated ASM code does result in an fld of an uninitialized local
variable, where looking on the C++ code such an access should not be possible.
If the content of the uninitialized local variable happens to be a SNaN by
accident (chances are very small, but not zero), an FPU exception happens. And
again, based on the C++ code no FPU exception should be possible (assuming d is
not an SNaN).

Here is a synthetic example that triggers the exception by "placing a bomb" on
the stack.

https://gcc.godbolt.org/z/aooex6dcT

Function place_bomb() has an effect on what happens in func(). That should not
be the case! This is all valid C++ code.

This may now accidentally happen in our application. The behavior is
unpredictable, because it depends on what previous function calls left on the
stack.

If you change "-march=i686" to "-march=i386" in the example linked above,
everything goes fine.

  parent reply	other threads:[~2021-10-13 17:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-93934-4@http.gcc.gnu.org/bugzilla/>
2021-10-13 10:20 ` vajdaz at protonmail dot com
2021-10-13 10:58 ` rguenth at gcc dot gnu.org
2021-10-13 12:50 ` ubizjak at gmail dot com
2021-10-13 13:39 ` vajdaz at protonmail dot com
2021-10-13 14:36 ` ubizjak at gmail dot com
2021-10-13 15:11 ` amonakov at gcc dot gnu.org
2021-10-13 17:54 ` vajdaz at protonmail dot com [this message]
2021-10-13 21:47 ` joseph at codesourcery dot com
2021-10-14  7:21 ` rguenth at gcc dot gnu.org
2021-10-14  8:42 ` ubizjak at gmail dot com
2021-10-14 10:05 ` vajdaz at protonmail dot com
2021-10-14 10:18 ` ubizjak at gmail dot com
2021-10-14 10:34 ` ubizjak at gmail dot com
2021-10-14 10:42 ` rguenther at suse dot de
2021-10-14 14:15 ` vajdaz at protonmail dot com
2021-10-14 16:26 ` joseph at codesourcery dot com
2021-10-14 18:00 ` ubizjak at gmail dot com

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=bug-93934-4-AZWudek7Zq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.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.
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).