From patchwork Thu Apr 28 07:13:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 53290 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD7FB3857C49 for ; Thu, 28 Apr 2022 07:13:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD7FB3857C49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651130016; bh=+OP0kCauPK8KI5umfYBAtfw0mZtCpWCcsaA74nEs/QE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=g4beU0deI1Oc3SCUFRbp3cFRGq+pyoPVNjlXUDTGaxYgadCWwHxUAHP0B6x5svTFr QtSka6VRwO0szf+St9ARuPaowMtgpxV84Lcu5HuHWcBxHaevRvBCHRYCFBLHOftwQB fsK1ZHo6hwcns7whFA3dFJWno9Eoo75sNEz6IY0k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 472493858D1E for ; Thu, 28 Apr 2022 07:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 472493858D1E Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 14FCA21871; Thu, 28 Apr 2022 07:13:06 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id E784413491; Thu, 28 Apr 2022 07:13:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id h41kN4E+amJ6ZAAAMHmgww (envelope-from ); Thu, 28 Apr 2022 07:13:05 +0000 Date: Thu, 28 Apr 2022 09:13:05 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] middle-end/105376 - invalid REAL_CST for DFP constant MIME-Version: 1.0 Message-Id: <20220428071305.E784413491@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Cc: Jakub Jelinek , "Joseph S. Myers" Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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. Bootstrapped and tested on x86_64-unknown-linux-gnu, OK for stage1 and eventual backporting (I'm considering making the gcc_unreachable conditional on flag_checking on release branches). Thanks, Richard. 2022-04-27 Richard Biener PR middle-end/105376 * tree.cc (build_real): Special case dconst* arguments for decimal floating point types. * gcc.dg/pr105376.c: New testcase. --- gcc/testsuite/gcc.dg/pr105376.c | 9 +++++++++ gcc/tree.cc | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr105376.c 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. */