From patchwork Wed Oct 9 20:26:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Kargl X-Patchwork-Id: 1174020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510572-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=troutmask.apl.washington.edu Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Sv+cXT7B"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46pQjB5v2Xz9s7T for ; Thu, 10 Oct 2019 07:26:21 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=W4B2Kk1hgTlSLHz4QqNp0+UbZa1J2qqu7Ekb6qvzMAn bzz6LrikL9hYBLFoi/4eCEfwYQOqbfdd6tC4Bwp23rI/iWeMgQX8APFhXQa9DxNf 5qVit4cza8EIHHwvVY7routRYSzh/P4tBaPpGASyySKC2si8lxmmCrD2DXtC7dHs = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=XQ0PWQQWvVJuhSX0SK4eDDbNSKs=; b=Sv+cXT7B3usjEgk3g jt7g5puWy+N8AMWa+SF24YtVuwnEHE3t8SXdvANaZnXBxzlCaqx1jjwoi6NNh7ox BmmCXPAsesSAz83hE4lFdhsQnWFbWaAXAjr/0yC7oXAHRLHTx3zuycVYl8/K4jFv 1dQtA0pdUtI9zf5FwVjibpa6jo= Received: (qmail 129635 invoked by alias); 9 Oct 2019 20:26:08 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 129617 invoked by uid 89); 9 Oct 2019 20:26:08 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy= 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; Wed, 09 Oct 2019 20:26:07 +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 x99KQ5Go055564 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 9 Oct 2019 13:26:05 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x99KQ5uE055563; Wed, 9 Oct 2019 13:26:05 -0700 (PDT) (envelope-from sgk) Date: Wed, 9 Oct 2019 13:26:05 -0700 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/92019 -- BOZ cannot be an array index Message-ID: <20191009202605.GA55552@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) The attach patch fixes an ICE caused by the use of a bOZ as an array index. Tested on x86_64-*-freebsd. OK to commit? 2019-10-09 Steven G. Kargl PR fortran/92019 * array.c (match_subscript): BOZ cannot be an array subscript. 2019-10-09 Steven G. Kargl PR fortran/92019 * gfortran.dg/pr92019.f90: New test. Index: gcc/fortran/array.c =================================================================== --- gcc/fortran/array.c (revision 276705) +++ gcc/fortran/array.c (working copy) @@ -66,6 +66,7 @@ match_subscript (gfc_array_ref *ar, int init, bool mat match m = MATCH_ERROR; bool star = false; int i; + bool saw_boz = false; i = ar->dimen + ar->codimen; @@ -91,6 +92,12 @@ match_subscript (gfc_array_ref *ar, int init, bool mat else if (!star) m = gfc_match_expr (&ar->start[i]); + if (ar->start[i] && ar->start[i]->ts.type == BT_BOZ) + { + gfc_error ("Invalid BOZ literal constant used in subscript at %C"); + saw_boz = true; + } + if (m == MATCH_NO) gfc_error ("Expected array subscript at %C"); if (m != MATCH_YES) @@ -117,6 +124,12 @@ end_element: else m = gfc_match_expr (&ar->end[i]); + if (ar->end[i] && ar->end[i]->ts.type == BT_BOZ) + { + gfc_error ("Invalid BOZ literal constant used in subscript at %C"); + saw_boz = true; + } + if (m == MATCH_ERROR) return MATCH_ERROR; @@ -132,6 +145,12 @@ end_element: m = init ? gfc_match_init_expr (&ar->stride[i]) : gfc_match_expr (&ar->stride[i]); + if (ar->stride[i] && ar->stride[i]->ts.type == BT_BOZ) + { + gfc_error ("Invalid BOZ literal constant used in subscript at %C"); + saw_boz = true; + } + if (m == MATCH_NO) gfc_error ("Expected array subscript stride at %C"); if (m != MATCH_YES) @@ -142,7 +161,7 @@ matched: if (star) ar->dimen_type[i] = DIMEN_STAR; - return MATCH_YES; + return (saw_boz ? MATCH_ERROR : MATCH_YES); } Index: gcc/testsuite/gfortran.dg/pr92019.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr92019.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr92019.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/92019 +program foo + integer :: a(4) = [1, 2, 3, 4] + print *, a(z'1') ! { dg-error "Invalid BOZ literal constant" } + print *, a(1:z'3') ! { dg-error "Invalid BOZ literal constant" } + print *, a(1:2:z'2') ! { dg-error "Invalid BOZ literal constant" } + print *, a([z'2',z'1']) ! { dg-error "cannot appear in an array constructor" } +end program foo