From patchwork Fri Apr 8 20:44:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1615066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LkGo9paG; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZqyV5rNTz9sFy for ; Sat, 9 Apr 2022 06:45:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB5483857815 for ; Fri, 8 Apr 2022 20:45:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB5483857815 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649450735; bh=83hHwh9MBgSEkeSUCWCiY5BVimjQNWlCDrePflCaoLA=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LkGo9paGbFDbQsB8uPNVdaRVmDfQVHTKHfZd2DasGtk4GmL2BByDJF0lRAaS3XwmV uwv97wolm/pDj3DcvZImTFhDnkxGUHTslul0TG3XtV+ZOTPdcKqa1+QXdyOf65fBq+ +W1iWEy9u59Thjxob74byOGDoryV4GZCSRoRYNeM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id 84E763858D28; Fri, 8 Apr 2022 20:44:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 84E763858D28 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.29] ([93.207.82.187]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MV67o-1nVsBd2nmI-00S9rD; Fri, 08 Apr 2022 22:44:55 +0200 Message-ID: <00368e5d-a283-0069-fa5e-1f0401516ddf@gmx.de> Date: Fri, 8 Apr 2022 22:44:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: [PATCH, v2] PR fortran/105184 - ICE in gfc_array_init_size, at fortran/trans-array.cc:5841 Content-Language: en-US To: fortran , gcc-patches Newsgroups: gmane.comp.gcc.fortran,gmane.comp.gcc.patches References: In-Reply-To: X-Provags-ID: V03:K1:XBH/o5nbHJ6tGkUYgino5OdQM3XOpYJZG08KcQHznnO6Y7sQzU/ hG9BDROrbEdYSzQyo9zQvm2LPP9LC356YkCw69rEsHrzeTKtbFWXxOO/QtlDajMW5C+Imd9 fjxgSycDFJIGovhEZkuJrAL5HHmsznIvsBIrhXKrsgiLbGxGSZTCSMMpZT/IjFh8Mm4wKRU A9U2f+sQf3oI5s4yNz17w== X-UI-Out-Filterresults: notjunk:1;V03:K0:ByctKwmNp2I=:Zfkbtx0yVXibKtg4UcSZw2 rqLOwsyLPe8213w2egGANpEa6VzMVc+WgnQYHahFspXeVJZ3PTGiDTEMuzwfcuzEAVNj4czBg xq9YueQIeq439lmrcvBowRL1hep1nHaZGzhHXehzmQTRmosK+hLCF5veQrHdh61llZoyJAVDz HaTq4j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_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear all, Am 06.04.22 um 22:30 schrieb Harald Anlauf via Fortran: > Dear all, > > the logic for checking the allocate-coshape-spec in an ALLOCATE > statement was sort of sideways, and allowed to pass invalid > specifications to the code generation. > > The fix seems obvious (to me). after submitting the previous patch, I found another invalid case with a missing lower bound which was still silently accepted. The attached revised patch adds this check, improves the original error message to actually point to the coarray specification, and renames the testcase to align better with existing coarray testcases. > Regtested on x86_64-pc-linux-gnu. OK for mainline? > (12 or wait for 13?). Regtested again with no new failures. OK for mainline? Thanks, Harald From 483cbf9942dcfcf74a912312dbbcda2f108200ea Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 6 Apr 2022 22:24:21 +0200 Subject: [PATCH] Fortran: fix checking of coshape specification in ALLOCATE statement gcc/fortran/ChangeLog: PR fortran/105184 * array.cc (match_subscript): Reject assumed size coarray specification with missing lower bound. * resolve.cc (resolve_allocate_expr): Fix logic for checking allocate-coshape-spec in ALLOCATE statement. gcc/testsuite/ChangeLog: PR fortran/105184 * gfortran.dg/coarray_44.f90: Adjust expected output. * gfortran.dg/coarray_allocate_11.f90: Likewise. * gfortran.dg/coarray_allocate_12.f90: New test. --- gcc/fortran/array.cc | 7 +++++++ gcc/fortran/resolve.cc | 11 ++++++----- gcc/testsuite/gfortran.dg/coarray_44.f90 | 2 ++ .../gfortran.dg/coarray_allocate_11.f90 | 6 +++--- .../gfortran.dg/coarray_allocate_12.f90 | 19 +++++++++++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/coarray_allocate_12.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index eb9ed8580a0..90ea812d699 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -134,6 +134,13 @@ end_element: if (m == MATCH_ERROR) return MATCH_ERROR; + if (star && ar->start[i] == NULL) + { + gfc_error ("Missing lower bound in assumed size " + "coarray specification at %C"); + return MATCH_ERROR; + } + /* See if we have an optional stride. */ if (gfc_match_char (':') == MATCH_YES) { diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 21c8797c938..05f8f1bf6c2 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -8108,12 +8108,13 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code, bool *array_alloc_wo_spec) goto failure; case DIMEN_RANGE: - if (ar->start[i] == 0 || ar->end[i] == 0) + /* F2018:R937: + * allocate-coshape-spec is [ lower-bound-expr : ] upper-bound-expr + */ + if (ar->start[i] == 0 || ar->end[i] == 0 || ar->stride[i] != NULL) { - /* If ar->stride[i] is NULL, we issued a previous error. */ - if (ar->stride[i] == NULL) - gfc_error ("Bad array specification in ALLOCATE statement " - "at %L", &e->where); + gfc_error ("Bad coarray specification in ALLOCATE statement " + "at %L", &e->where); goto failure; } else if (gfc_dep_compare_expr (ar->start[i], ar->end[i]) == 1) diff --git a/gcc/testsuite/gfortran.dg/coarray_44.f90 b/gcc/testsuite/gfortran.dg/coarray_44.f90 index 15fb8c76ce4..545b5462251 100644 --- a/gcc/testsuite/gfortran.dg/coarray_44.f90 +++ b/gcc/testsuite/gfortran.dg/coarray_44.f90 @@ -10,3 +10,5 @@ program pr70071 allocate (z(2)[1::2,*]) ! { dg-error "Bad array dimension" } allocate (z(1::2)[2,*]) ! { dg-error "Bad array specification in ALLOCATE" } end program pr70071 + +! { dg-prune-output "Bad coarray specification in ALLOCATE statement" } diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 b/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 index 0e806f0955b..0e4f64e1e3d 100644 --- a/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 +++ b/gcc/testsuite/gfortran.dg/coarray_allocate_11.f90 @@ -3,10 +3,10 @@ program p integer, allocatable :: z[:,:] integer :: i - allocate (z[1:,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } - allocate (z[:2,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } + allocate (z[1:,*]) ! { dg-error "Bad coarray specification in ALLOCATE statement" } + allocate (z[:2,*]) ! { dg-error "Bad coarray specification in ALLOCATE statement" } allocate (z[2:1,*]) ! { dg-error "Upper cobound is less than lower cobound" } - allocate (z[:0,*]) ! { dg-error "Bad array specification in ALLOCATE statement" } + allocate (z[:0,*]) ! { dg-error "Bad coarray specification in ALLOCATE statement" } allocate (z[0,*]) ! { dg-error "Upper cobound is less than lower cobound" } allocate (z[1,*]) ! This is OK allocate (z[1:1,*]) ! This is OK diff --git a/gcc/testsuite/gfortran.dg/coarray_allocate_12.f90 b/gcc/testsuite/gfortran.dg/coarray_allocate_12.f90 new file mode 100644 index 00000000000..2169aa19998 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coarray_allocate_12.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! +! PR fortran/105184 +! Based on testcases by Gerhard Steinmetz + +program p + real, allocatable :: x[:,:] + integer :: n = 2 + allocate (x[ n, *]) + allocate (x[1:n, *]) + allocate (x[n:n, *]) + allocate (x[n, 5:*]) + allocate (x[ :n, *]) ! { dg-error "Bad coarray specification" } + allocate (x[::n, *]) ! { dg-error "Bad coarray specification" } + allocate (x[ :1:1, *]) ! { dg-error "Bad coarray specification" } + allocate (x[1:n:n, *]) ! { dg-error "Bad coarray specification" } + allocate (x[1, : *]) ! { dg-error "Missing lower bound" } +end -- 2.34.1