From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57490 invoked by alias); 1 Nov 2015 19:24:29 -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 57462 invoked by uid 89); 1 Nov 2015 19:24:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Sun, 01 Nov 2015 19:24:24 +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 tA1JOLQI006368 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 1 Nov 2015 11:24:21 -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 tA1JOLRO006367; Sun, 1 Nov 2015 11:24:21 -0800 (PST) (envelope-from sgk) Date: Sun, 01 Nov 2015 19:24:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Pr fortran/68153 -- Enhance checking of RESHAPE shape arg Message-ID: <20151101192421.GA6348@troutmask.apl.washington.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-IsSubscribed: yes X-SW-Source: 2015-11/txt/msg00000.txt.bz2 --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 441 The attached patch enhances the check of the shape argument when it is a named constant. See the testcase for example. Built and regression tested on i386-*-freebsd. OK to commit? 2015-11-01 Steven G. Kargl PR fortran/68153 * check.c (gfc_check_reshape): Improve check for valid SHAPE argument. 2015-11-01 Steven G. Kargl PR fortran/68153 * gfortran.dg/pr68153.f90: New test. -- Steve --J/dobhs11T7y2rNN Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pr68153.diff" Content-length: 1776 Index: gcc/fortran/check.c =================================================================== --- gcc/fortran/check.c (revision 229634) +++ gcc/fortran/check.c (working copy) @@ -3711,6 +3711,36 @@ gfc_check_reshape (gfc_expr *source, gfc } } } + else if (shape->expr_type == EXPR_VARIABLE && shape->ref + && shape->ref->u.ar.type == AR_FULL && shape->ref->u.ar.dimen == 1 + && shape->ref->u.ar.as + && shape->ref->u.ar.as->lower[0]->expr_type == EXPR_CONSTANT + && shape->ref->u.ar.as->lower[0]->ts.type == BT_INTEGER + && shape->ref->u.ar.as->upper[0]->expr_type == EXPR_CONSTANT + && shape->ref->u.ar.as->upper[0]->ts.type == BT_INTEGER + && shape->symtree->n.sym->attr.flavor == FL_PARAMETER) + { + int i, dim; + gfc_expr *e, *v; + + v = shape->symtree->n.sym->value; + + for (i = 0; i < shape_size; i++) + { + e = gfc_constructor_lookup_expr (v->value.constructor, i); + if (e == NULL) + break; + + gfc_extract_int (e, &dim); + + if (dim < 0) + { + gfc_error ("Element %d of actual argument of RESHAPE at %L " + "cannot be negative", i + 1, &shape->where); + return false; + } + } + } if (pad != NULL) { Index: gcc/testsuite/gfortran.dg/pr68153.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr68153.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/pr68153.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/68153 +! Original code contribute by Gerhard Steinmetz +! +! +program foo + integer, parameter :: a(2) = [2, -2] + integer, parameter :: b(2,2) = reshape([1, 2, 3, 4], a) ! { dg-error "cannot be negative" } +end program foo --J/dobhs11T7y2rNN--