From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id 58BAF3858D3C; Wed, 1 Mar 2023 09:40:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58BAF3858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.98,224,1673942400"; d="scan'208";a="99910745" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa2.mentor.iphmx.com with ESMTP; 01 Mar 2023 01:40:24 -0800 IronPort-SDR: gxf6ZtOggCDdW+v61lfmKGvTLTVAoAOS5PRpRMXU54I94MwC78ZL1ZTVtOORTGJpcf+v5/HuSF 8cMa83K1azygOvT9RA1FNS/W+eX0Wu77t+8pfoHD1yE+NsdIRz8xha2+wST+PEe5PQQTeE3KBv vadIOhP0MCl5Z9aTLDBolQJvKbhfVRCAJxpUo0Ide7i14bSZlZmvBHLWIe0IMBbyN8ADn+CrE+ BsB87m5lmO8m34SHUf3w+gI2QyEgIuwFK29VNrKy0ViXMQj4bYgglpI994sZU/QoOtR+RsHt6m vHU= Message-ID: Date: Wed, 1 Mar 2023 10:40:15 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: Re: [PATCH, gfortran] Escalate failure when Hollerith constant to real conversion fails [PR103628] Content-Language: en-US To: HAO CHEN GUI , gcc-patches , fortran CC: Segher Boessenkool , David , Kewen.Lin , Peter Bergner References: From: Tobias Burnus In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,KAM_SHORT,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi, Please CC fortran@gcc for Fortran patches. Fortraners: Please see my add-on suggestion/.diff for 'do_simply' below and the original email at https://gcc.gnu.org/pipermail/gcc-patches/2023-March/613019.html On 01.03.23 08:09, HAO CHEN GUI via Gcc-patches wrote: > The patch escalates the failure when Hollerith constant to real conversio= n > fails in native_interpret_expr. It finally reports an "Unclassifiable > statement" error. I think we should do better than this (cf. below). > The patch of pr95450 added a verification for decoding/encoding checki= ng > in native_interpret_expr. native_interpret_expr may fail on real type > conversion and returns a NULL tree then. But upper layer calls don't hand= le > the failure so that an ICE is reported when the verification fails. > > IBM long double is an example. It doesn't have a unique memory present= ation > for some real values. So it may not pass the verification. The new test > case shows the problem. > > Bootstrapped and tested on powerpc64-linux BE and LE with no regressions. I think the patch OK except for two items: > ChangeLog > 2023-03-01 Haochen Gui > > gcc/ > PR target/103628 > * fortran/target-memory.cc (gfc_interpret_float): Return FAIL when > native_interpret_expr gets a NULL tree. > * fortran/arith.cc (gfc_hollerith2real): Return NULL when > gfc_interpret_float fails. > > gcc/testsuite/ > PR target/103628 > * gfortran.dg/pr103628.f90: New. ... > --- a/gcc/fortran/target-memory.cc > +++ b/gcc/fortran/target-memory.cc > @@ -417,10 +417,13 @@ gfc_interpret_float (int kind, unsigned char *buffe= r, size_t buffer_size, > { > gfc_set_model_kind (kind); > mpfr_init (real); > - gfc_conv_tree_to_mpfr (real, > - native_interpret_expr (gfc_get_real_type (kind), > - buffer, buffer_size)); > > + tree source =3D native_interpret_expr (gfc_get_real_type (kind), buff= er, > + buffer_size); > + if (!source) > + return 0; > + > + gfc_conv_tree_to_mpfr (real, source); Can you move the mpfr_init before the 'gfc_conv...mfpr' to avoid pointless allocation/leaks by mpfr_init. > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/pr103628.f90 > @@ -0,0 +1,14 @@ > +! { dg-do compile { target powerpc*-*-* } } > +! { dg-options "-O2 -mabi=3Dibmlongdouble" } > + > +! Test to ensure that it reports an "Unclassifiable statement" error > +! instead of throwing an ICE when the memory represent of the HOLLERITH > +! string is not unique with ibm long double encoding. > ... > + real(kind =3D k):: b =3D 4h1234 > ... > +! { dg-warning "Conversion from HOLLERITH" "warning" { target powerpc*-*= -* } 10 } > +! { dg-error "Unclassifiable statement" "error" { target powerpc*-*-* } = 10 } I find a generic error pointing to the beginning of the line not that helpf= ul. I did wonder about something specific, but at the end for a rather special = case, a generic catch-all for 'do_simplify' seems to make sense. The callers of '= do_simplify' clearly assume that this function will always (indirectly) generate an erro= r message if an error occurs. With my change, the result is: 10 | real(kind =3D k):: b =3D 4h1234 | 1 Error: Cannot simplify expression at (1) That's with: diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc index 64821c84543..b60d92a0665 100644 --- a/gcc/fortran/intrinsic.cc +++ b/gcc/fortran/intrinsic.cc @@ -27,2 +27,3 @@ along with GCC; see the file COPYING3. If not see #include "intrinsic.h" +#include "diagnostic.h" /* For errorcount. */ @@ -4622,2 +4623,3 @@ do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e= ) gfc_actual_arglist *arg; + int old_errorcount =3D errorcount; @@ -4710,3 +4712,7 @@ finish: if (result =3D=3D &gfc_bad_expr) - return false; + { + if (errorcount =3D=3D old_errorcount) + gfc_error ("Cannot simplify expression at %L", &e->where); + return false; + } Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstra=C3=9Fe 201= , 80634 M=C3=BCnchen; Gesellschaft mit beschr=C3=A4nkter Haftung; Gesch=C3= =A4ftsf=C3=BChrer: Thomas Heurung, Frank Th=C3=BCrauf; Sitz der Gesellschaf= t: M=C3=BCnchen; Registergericht M=C3=BCnchen, HRB 106955