public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail 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: Thu, 14 Oct 2021 10:18:17 +0000 [thread overview]
Message-ID: <bug-93934-4-Y68VnyBy99@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 #20 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to joseph@codesourcery.com from comment #16)
> I don't think this bug is anything to do with -fsignaling-nans, for the
> same reason as applies to bug 58416 and bug 71460.
The situation is hopeless from the beginning. Please consider this testcase:
--cut here--
#include <cpuid.h>
#include <fenv.h>
double
__attribute__((noinline,noipa))
foo (double a, double b, char c)
{
return c ? a : b;
}
int main ()
{
double a = __builtin_nans ("");
double b = 42.0;
feclearexcept (FE_INVALID);
foo (a, b, 0);
if (fetestexcept (FE_INVALID))
__builtin_abort ();
return 0;
}
--cut here--
$ gcc -O2 -m32 -march=i686 -lm fcmov.c
$ ./a.out
Aborted (core dumped)
$ gcc -O2 -m32 -march=i386 -lm fcmov.c
$ ./a.out
Aborted (core dumped)
Because the compiler generates:
foo:
cmpb $0, 20(%esp)
fldl 12(%esp)
fldl 4(%esp)
fcmove %st(1), %st
fstp %st(1)
ret
in the former case and:
foo:
fldl 4(%esp)
fldl 12(%esp)
cmpb $0, 20(%esp)
jne .L4
fstp %st(1)
jmp .L2
.L4:
fstp %st(0)
.L2:
ret
in the later.
Since the ABI specifies the operand size on the stack, the above code will
always trap.
next prev parent reply other threads:[~2021-10-14 10:18 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
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 [this message]
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-Y68VnyBy99@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).