public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8348] middle-end/105376 - invalid REAL_CST for DFP constant Date: Fri, 6 May 2022 10:30:01 +0000 (GMT) [thread overview] Message-ID: <20220506103001.1334D38485AA@sourceware.org> (raw) https://gcc.gnu.org/g:39c56695c70a2052fc6bdcfca606dfff9c2fa975 commit r12-8348-g39c56695c70a2052fc6bdcfca606dfff9c2fa975 Author: Richard Biener <rguenther@suse.de> Date: Wed Apr 27 08:28:31 2022 +0200 middle-end/105376 - invalid REAL_CST for DFP constant We are eventually ICEing in decimal_to_decnumber on non-decimal REAL_VALUE_TYPE that creep in from uses of build_real (..., dconst*) for DFP types. The following extends the decimal_to_decnumber special-casing of dconst* to build_real, avoiding the bogus REAL_CSTs from creeping into the IL and modified to ones not handled by the decimal_to_decnumber special casing. It also makes sure to ICE for not handled dconst* values at the point we build the REAL_CST. 2022-04-27 Richard Biener <rguenther@suse.de> PR middle-end/105376 * tree.cc (build_real): Special case dconst* arguments for decimal floating point types. * gcc.dg/pr105376.c: New testcase. (cherry picked from commit e27eef7478f30ea79048dbde3317e89679d75a6e) Diff: --- gcc/testsuite/gcc.dg/pr105376.c | 9 +++++++++ gcc/tree.cc | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/gcc/testsuite/gcc.dg/pr105376.c b/gcc/testsuite/gcc.dg/pr105376.c new file mode 100644 index 00000000000..f19ecf4aab2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr105376.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target dfp } } */ +/* { dg-options "-O -g" } */ + +void +foo (_Decimal64 d, _Decimal64 e) +{ + d -= -d; + d *= -e; +} diff --git a/gcc/tree.cc b/gcc/tree.cc index 3c39be4f501..4cf3785270b 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -70,6 +70,7 @@ along with GCC; see the file COPYING3. If not see #include "escaped_string.h" #include "gimple-range.h" #include "gomp-constants.h" +#include "dfp.h" /* Tree code classes. */ @@ -2383,6 +2384,26 @@ build_real (tree type, REAL_VALUE_TYPE d) REAL_VALUE_TYPE *dp; int overflow = 0; + /* dconst{1,2,m1,half} are used in various places in + the middle-end and optimizers, allow them here + even for decimal floating point types as an exception + by converting them to decimal. */ + if (DECIMAL_FLOAT_MODE_P (TYPE_MODE (type)) + && d.cl == rvc_normal + && !d.decimal) + { + if (memcmp (&d, &dconst1, sizeof (d)) == 0) + decimal_real_from_string (&d, "1"); + else if (memcmp (&d, &dconst2, sizeof (d)) == 0) + decimal_real_from_string (&d, "2"); + else if (memcmp (&d, &dconstm1, sizeof (d)) == 0) + decimal_real_from_string (&d, "-1"); + else if (memcmp (&d, &dconsthalf, sizeof (d)) == 0) + decimal_real_from_string (&d, "0.5"); + else + gcc_unreachable (); + } + /* ??? Used to check for overflow here via CHECK_FLOAT_TYPE. Consider doing it via real_convert now. */
reply other threads:[~2022-05-06 10:30 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220506103001.1334D38485AA@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@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: linkBe 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).