From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 125B23858D33; Fri, 3 Mar 2023 09:30:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 125B23858D33 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,230,1673942400"; d="scan'208";a="98852109" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa4.mentor.iphmx.com with ESMTP; 03 Mar 2023 01:30:00 -0800 IronPort-SDR: lb+tpvUf2pJhQZQ8Qh/dxCLuj6E41YUkXVpR03KtHsu3EjrDNVFsfQPf2k+d/WkVz8O5DHBib4 3jtqfVCRyxDwC7Q+ld417/KVoPivpMEru8Xt2LRjy3APCOrA5t1dzENyDWTI4CfkbbjMoLTyZj 4nSkri4/zxUo65aiC5w7+E8c0HRMhZXnoaB0uE7wqHr67CnGazLs+INQFyRYzKyj7+uWbcqTse yyLDdigu5aPW6MNL/Bk2W+fJ9NgY+LWreHfW5Hwo3ao8TYOX/hkfGcNiztxM9EdYObM0FyOsfY S/k= Message-ID: <5049d46a-5edb-42c1-798a-b21410f6bdc0@codesourcery.com> Date: Fri, 3 Mar 2023 10:29:52 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCHv2, 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-13.mgc.mentorg.com (139.181.222.13) 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,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 Haochen, thanks for fixing 'gcc/fortran/target-memory.cc'. But could you also include the 'gcc/fortran/intrinsic.cc' change proposed in https://gcc.gnu.org/pipermail/gcc-patches/2023-March/613030.html (and acknowledged by Steve)? This will replace "Unclassifiable statement" by "Cannot simplify expression" which is a bit more helpful. (After doing so, at least the dg-error in your testcase needs to be updated; I assume that it won't affect other testcases, but that needs to be checked. =E2=80=93 And you should update the comment in the testcase = as well - and in text you will put in the commit log, if applicable.) Additionally, Kewen suggested: > Since this test case is powerpc only, I think it can be moved to gcc/test= suite/gcc.target/powerpc/ppc-fortran. Which sounds reasonable. Otherwise it looks good to me. On 03.03.23 10:12, HAO CHEN GUI wrote: > Hi, > The patch escalates the failure when Hollerith constant to real conver= sion > fails in native_interpret_expr. It finally reports an "Unclassifiable > statement" error. > > 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. > > Compared to last version, this version moves the mpfr_init after NULL = tree > test and fixes the format problem according to Tobias's advice. Thanks a = lot. (The format issue was actually spotted by Bernhard.) Thanks for working on this! Tobias PS: One can also discuss Steve's suggestion about deprecating Holleriths / = guarding the support behind some flag. But I think that's unrelated to this bug fix = patch and should be discussed/done separately. > 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. > > patch.diff > diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc > index c0d12cfad9d..d3d38c7eb6a 100644 > --- a/gcc/fortran/arith.cc > +++ b/gcc/fortran/arith.cc > @@ -2752,10 +2752,12 @@ gfc_hollerith2real (gfc_expr *src, int kind) > result =3D gfc_get_constant_expr (BT_REAL, kind, &src->where); > > hollerith2representation (result, src); > - gfc_interpret_float (kind, (unsigned char *) result->representation.st= ring, > - result->representation.length, result->value.real); > - > - return result; > + if (gfc_interpret_float (kind, > + (unsigned char *) result->representation.string, > + result->representation.length, result->value.rea= l)) > + return result; > + else > + return NULL; > } > > /* Convert character to real. The constant will be padded or truncated= . */ > diff --git a/gcc/fortran/target-memory.cc b/gcc/fortran/target-memory.cc > index 7ce7d736629..0c47aa6b842 100644 > --- a/gcc/fortran/target-memory.cc > +++ b/gcc/fortran/target-memory.cc > @@ -416,11 +416,14 @@ gfc_interpret_float (int kind, unsigned char *buffe= r, size_t buffer_size, > mpfr_t real) > { > 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), buffe= r, > + buffer_size); > + if (!source) > + return 0; > + > + mpfr_init (real); > + gfc_conv_tree_to_mpfr (real, source); > return size_float (kind); > } > > diff --git a/gcc/testsuite/gfortran.dg/pr103628.f90 b/gcc/testsuite/gfort= ran.dg/pr103628.f90 > new file mode 100644 > index 00000000000..e49aefc18fd > --- /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. > + > +program main > + integer, parameter :: k =3D 16 > + real(kind =3D k):: b =3D 4h1234 > +end program main > + > +! { dg-warning "Conversion from HOLLERITH" "warning" { target powerpc*-*= -* } 10 } > +! { dg-error "Unclassifiable statement" "error" { target powerpc*-*-* } = 10 } ----------------- 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