From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id B74F63858C2B; Mon, 20 Mar 2023 02:12:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B74F63858C2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32K1YWQj016915; Mon, 20 Mar 2023 02:12:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : from : to : cc : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=pSnkaTjhEFV9pPSCgX/64fkzqgMGFUjVk/lNjNG25VU=; b=ZEni5U0mgJqCfQ6SpLXQ7mjI+65oHBo7+nDDlGN0qUraQZG1QcSN5E/riYo/tWg7x7Vp 9KM3ivbem2eNH2QAqFnBqwA+A1dSfGWXe8QnXbg9wFNmJoXXK3nWC5JaQHBzCsLUSw5t uDArpUGrVNaI8OBqV9zWNAOGlWACcLqlXwXoOw335m7ND0OWlnakWWFN4llOPVqMQ1Zd WsmlyiOLDq0I+WyxGgG29y25+wmIAhIdt+l0ZeO0pN9yRA64QYQzUHBTytf2R+AzKb09 FT9xTaI1eMnJLStw4NGzzKXw+WuK/E/M3hjvPsxjjG1PbXpZfR+kNY/YsVxrtTVjfBh5 Pg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pdq3tbdfn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 02:12:23 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 32K23ZPF007717; Mon, 20 Mar 2023 02:12:22 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pdq3tbdf6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 02:12:22 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32JAMr9S016541; Mon, 20 Mar 2023 02:12:20 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3pd4x6ahj6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 20 Mar 2023 02:12:20 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32K2CGo9393790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 20 Mar 2023 02:12:16 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6E3BA20049; Mon, 20 Mar 2023 02:12:16 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D928B20040; Mon, 20 Mar 2023 02:12:13 +0000 (GMT) Received: from [9.197.230.70] (unknown [9.197.230.70]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 20 Mar 2023 02:12:13 +0000 (GMT) Message-ID: <8814c31b-e16a-5a20-4339-f5315d0583b7@linux.ibm.com> Date: Mon, 20 Mar 2023 10:12:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Ping [PATCHv3, gfortran] Escalate failure when Hollerith constant to real conversion fails [PR103628] From: HAO CHEN GUI To: gcc-patches , fortran Cc: Segher Boessenkool , David , "Kewen.Lin" , Peter Bergner , Tobias Burnus References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: sB_b5ee6X_VT2Q2gMEBV-OEGqhN3RelF X-Proofpoint-GUID: gbC4Clyhjl7vKWMotrreKL5xhIU30wfW Content-Transfer-Encoding: 8bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-19_14,2023-03-16_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303200017 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,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, Gently ping this: https://gcc.gnu.org/pipermail/gcc-patches/2023-March/613497.html Thanks Gui Haochen 在 2023/3/7 16:55, HAO CHEN GUI 写道: > Hi, > The patch escalates the failure when Hollerith constant to real conversion > fails in native_interpret_expr. It finally reports an "Cannot simplify > expression" error in do_simplify method. > > The patch of pr95450 added a verification for decoding/encoding checking > 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 handle > 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 presentation > for some real values. So it may not pass the verification. The new test > case shows the problem. > > errorcount is used to check if an error is already reported or not when > getting a bad expr. Buffered errors need to be excluded as they don't > increase error count either. > > The patch passed regression test on Power and x86 linux platforms. > > Gui Haochen > Thanks > > ChangeLog > 2023-03-07 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. > * fortran/error.cc (gfc_buffered_p): Define. > * fortran/gfortran.h (gfc_buffered_p): Declare. > * fortran/intrinsic.cc: Add diagnostic.h to include list. > (do_simplify): Save errorcount and check it at finish. Report a > "Cannot simplify expression" error on a bad result if error count > doesn't change and no other errors buffered. > > gcc/testsuite/ > PR target/103628 > * gfortran.dg/pr103628.f90: New. > > Co-Authored-By: Tobias Burnus > > 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 = gfc_get_constant_expr (BT_REAL, kind, &src->where); > > hollerith2representation (result, src); > - gfc_interpret_float (kind, (unsigned char *) result->representation.string, > - result->representation.length, result->value.real); > - > - return result; > + if (gfc_interpret_float (kind, > + (unsigned char *) result->representation.string, > + result->representation.length, result->value.real)) > + return result; > + else > + return NULL; > } > > /* Convert character to real. The constant will be padded or truncated. */ > diff --git a/gcc/fortran/error.cc b/gcc/fortran/error.cc > index 214fb78ba7b..872d42e731e 100644 > --- a/gcc/fortran/error.cc > +++ b/gcc/fortran/error.cc > @@ -49,6 +49,13 @@ static gfc_error_buffer error_buffer; > static output_buffer *pp_error_buffer, *pp_warning_buffer; > static int warningcount_buffered, werrorcount_buffered; > > +/* Return buffered_p. */ > +bool > +gfc_buffered_p (void) > +{ > + return buffered_p; > +} > + > /* Return true if there output_buffer is empty. */ > > static bool > diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h > index 219ef8c7612..edfe11796a6 100644 > --- a/gcc/fortran/gfortran.h > +++ b/gcc/fortran/gfortran.h > @@ -3328,6 +3328,7 @@ void gfc_internal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_GCC_GFC > void gfc_clear_error (void); > bool gfc_error_check (void); > bool gfc_error_flag_test (void); > +bool gfc_buffered_p (void); > > notification gfc_notification_std (int); > bool gfc_notify_std (int, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); > diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc > index e89131f5a71..9d049001a51 100644 > --- a/gcc/fortran/intrinsic.cc > +++ b/gcc/fortran/intrinsic.cc > @@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see > #include "options.h" > #include "gfortran.h" > #include "intrinsic.h" > +#include "diagnostic.h" /* For errorcount. */ > > /* Namespace to hold the resolved symbols for intrinsic subroutines. */ > static gfc_namespace *gfc_intrinsic_namespace; > @@ -4620,6 +4621,7 @@ do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e) > { > gfc_expr *result, *a1, *a2, *a3, *a4, *a5, *a6; > gfc_actual_arglist *arg; > + int old_errorcount = errorcount; > > /* Max and min require special handling due to the variable number > of args. */ > @@ -4708,7 +4710,12 @@ do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e) > > finish: > if (result == &gfc_bad_expr) > - return false; > + { > + if (errorcount == old_errorcount > + && (gfc_buffered_p () && !gfc_error_flag_test ())) > + gfc_error ("Cannot simplify expression at %L", &e->where); > + return false; > + } > > if (result == NULL) > resolve_intrinsic (specific, e); /* Must call at run-time */ > 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 *buffer, 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 = native_interpret_expr (gfc_get_real_type (kind), buffer, > + 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/gfortran.dg/pr103628.f90 > new file mode 100644 > index 00000000000..255d5bdd73e > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/pr103628.f90 > @@ -0,0 +1,14 @@ > +! { dg-do compile { target powerpc*-*-* } } > +! { dg-options "-O2 -mabi=ibmlongdouble" } > + > +! Test to ensure that it reports an "Cannot simplify expression" 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 = 16 > + real(kind = k):: b = 4h1234 > +end program main > + > +! { dg-warning "Conversion from HOLLERITH" "warning" { target powerpc*-*-* } 10 } > +! { dg-error "Cannot simplify expression" "error" { target powerpc*-*-* } 10 } >