From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8720 invoked by alias); 10 Mar 2018 05:13:51 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 8702 invoked by uid 89); 10 Mar 2018 05:13:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.0 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*MI:sk:2018031 X-Spam-User: qpsmtpd, 2 recipients X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 10 Mar 2018 05:13:49 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id w2A5DlPn035590 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 9 Mar 2018 21:13:47 -0800 (PST) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id w2A5Dl39035589; Fri, 9 Mar 2018 21:13:47 -0800 (PST) (envelope-from sgk) Date: Sat, 10 Mar 2018 05:13:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] PR fortran/84734 -- Fix ICE on invalid code Message-ID: <20180310051347.GB35527@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu References: <20180310051310.GA35527@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tKW2IUtsqtDRztdT" Content-Disposition: inline In-Reply-To: <20180310051310.GA35527@troutmask.apl.washington.edu> User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes X-SW-Source: 2018-03/txt/msg00027.txt.bz2 --tKW2IUtsqtDRztdT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 1351 On Fri, Mar 09, 2018 at 09:13:10PM -0800, Steve Kargl wrote: > In fixing PR fortran/83633, it seems the patch I committed > introduced an ICE for nonsensical invalid Fortran. The > attached patch cures the ICE and now (re)issues an error > message. > > The basic problem seems to boil down to the recursive > calling of gfc_simplify_expr reduces "huge(1_8)+1_8" to > "constant + constant". When the chain of gfc_simplify_expr > tries to reduces this expression an overflow occurs. An > error message is queud but never emitted, and the result > is set to NULL and both constants are freed. The NULL is > passed back up through the chain of gfc_simplify_expr. > At some point that NULL pointer is referenced. The patch > works around the problem by passing the result with the > overflow value up the chain. > > Regression tested on x86_64-*-freebsd. I intend to commit > this patch tomorrow, which on my clock is only 2.75 hours > away. > > 2018-03-09 Steven G. Kargl > > PR fortran/84734 > * arith.c (check_result, eval_intrinsic): If result overflows, pass > the expression up the chain instead of a NULL pointer. > > 2018-03-09 Steven G. Kargl > > PR fortran/84734 > * gfortran.dg/pr84734.f90: New test. > Now with an attached patch. -- Steve --tKW2IUtsqtDRztdT Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pr84734.diff" Content-length: 1096 Index: gcc/fortran/arith.c =================================================================== --- gcc/fortran/arith.c (revision 258367) +++ gcc/fortran/arith.c (working copy) @@ -555,10 +555,10 @@ check_result (arith rc, gfc_expr *x, gfc_expr *r, gfc_ val = ARITH_OK; } - if (val != ARITH_OK) - gfc_free_expr (r); - else + if (val == ARITH_OK || val == ARITH_OVERFLOW) *rp = r; + else + gfc_free_expr (r); return val; } @@ -1603,8 +1603,12 @@ eval_intrinsic (gfc_intrinsic_op op, if (rc != ARITH_OK) { gfc_error (gfc_arith_error (rc), &op1->where); + if (rc == ARITH_OVERFLOW) + goto done; return NULL; } + +done: gfc_free_expr (op1); gfc_free_expr (op2); Index: gcc/testsuite/gfortran.dg/pr84734.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr84734.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr84734.f90 (working copy) @@ -0,0 +1,4 @@ +! { dg-do compile } +! PR fortran/84734 + integer :: b(huge(1_8)+1_8) = 0 ! { dg-error "Arithmetic overflow" } + end --tKW2IUtsqtDRztdT--