From patchwork Sun Dec 11 22:33:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 32216 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1940026wrr; Sun, 11 Dec 2022 14:35:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf65PTCaf6sWV9KgR9DpwvMXvIhw6j6I9iUkyI1ENVobIn4RoIQ96pMislxCe9NHSq2Pxu4Q X-Received: by 2002:a17:907:2e01:b0:7c1:4785:d650 with SMTP id ig1-20020a1709072e0100b007c14785d650mr7915949ejc.26.1670798155619; Sun, 11 Dec 2022 14:35:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670798155; cv=none; d=google.com; s=arc-20160816; b=FQXZLSJ+YOsSWExg6n0ZydTdWTfYzKbQPHJlip4GtRaaqTOzg9R6JLWoqNGMWqHW6q QZYCMqPiwYPBg+V5aaTYm0+5ocJ2xuHQ1X00MAwZvIU24anNwJD4tqlANJ3qw27FO+zH T8N3AAADp1hn0KhrfZhhUnLnhBZzfg6koKpLfKpw4kcQZjGgUoS3kezLkITkAbwMA9+B hScPgDdCE+QS3OziYb5Yob9SW/LWOY0bzr/Ba3xl+KVBdy1DWFxmYN+v3HasLS7K0Nvp jn82ccREdpbmY68bdgMyUC2RxN3mJ0EJpJmoj5qH18CRKA5GJxxP1kBojqFs16IvgLMw wZqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=i9Dt9pqm+2mHAyEFViBT3YsuZT5kt2bP8vNqQ14Xom0=; b=zinQGxnfr9afhfnMLxQKElx1dx6YjA3CclhNuO6BMjOwnQ7NggxKbJ0uHkG/GlQNwX X8j4P7hHGwMdXc6xyFhdNCJaQQWXQhyegYXdttrkfa45WEbyBypZg25oC6G+ShWHT7oB iZT+KVCgqi1Pvm3ctZtsGxstdLiWD1gVOikjz6BstxgG2y12e+euLlYusCF+6BJDjo04 dOxtdr0L2A7pA77glxNdyCY7B0tctV06+771NAwrx97pX1cqrwXULvr9+AwH0vd6xTec JI7eAkzHjVLESR9t7vvfkJocsGXbG5k+CDQ+lKLDTU7+vdzEWyYQTnnA2995gveVCbap r/LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i3g6WkYk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id nd33-20020a17090762a100b007c0d5b8443dsi5401257ejc.776.2022.12.11.14.35.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Dec 2022 14:35:55 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=i3g6WkYk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92F06380D706 for ; Sun, 11 Dec 2022 22:35:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92F06380D706 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670798131; bh=i9Dt9pqm+2mHAyEFViBT3YsuZT5kt2bP8vNqQ14Xom0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=i3g6WkYkvgPFiQugRUDau3s3EO+t8O71yiULd/dPWXJukrBXbTwSrIZUOguKXOPy0 HOfsiMxMfqolu3HiIZDiy4Mh5ukrAqBXvWZ/M/jnQWHh/ri9V6EWfZrTn6Hy0kE3ng UcwzrBu1vSw40HvoPGQ65mAx/B15p2AikI02K1M0= 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.17.22]) by sourceware.org (Postfix) with ESMTPS id 59474387722C; Sun, 11 Dec 2022 22:33:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59474387722C X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.87.138] ([93.207.87.138]) by web-mail.gmx.net (3c-app-gmx-bap41.server.lan [172.19.172.111]) (via HTTP); Sun, 11 Dec 2022 23:33:43 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: improve checking of assumed size array spec [PR102180] Date: Sun, 11 Dec 2022 23:33:43 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:wbS+HE88ZtEd7VF42Lp0CYd7BS6d+LM7y5QXrx3ktH10/vv/L8Rn1myxDozzP0IQIsYPH 3uCHqCG3UC0+fC8T0d2lrKJEk8EYpJEv6+XoGfs8JSps1YlQorNLGY7DTYddjXVVQ0GR3sPs5VVU eKT6m6BYcxLerYsUUgLd5/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M_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751958846686704280?= X-GMAIL-MSGID: =?utf-8?q?1751958846686704280?= Dear all, the attached patch improves checking of array specs in two ways: - bad assumed size array spec - a bad first array element spec may already trigger an error, leading to a more consistent behavior Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 06c1d0a96544640c7b1485fe977337ef1572ac91 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 11 Dec 2022 23:24:03 +0100 Subject: [PATCH] Fortran: improve checking of assumed size array spec [PR102180] gcc/fortran/ChangeLog: PR fortran/102180 * array.cc (match_array_element_spec): Add check for bad assumed-implied-spec. (gfc_match_array_spec): Reorder logic so that a first bad array element spec may trigger an error. gcc/testsuite/ChangeLog: PR fortran/102180 * gfortran.dg/pr102180.f90: New test. --- gcc/fortran/array.cc | 12 ++++++++++-- gcc/testsuite/gfortran.dg/pr102180.f90 | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr102180.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index bbdb5b392fc..9c1d55fa8cc 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -488,6 +488,14 @@ match_array_element_spec (gfc_array_spec *as) return AS_ASSUMED_SIZE; } + /* F2018:R821: "assumed-implied-spec is [ lower-bound : ] *". */ + if (gfc_match (" : * ") == MATCH_YES) + { + gfc_error ("A lower bound must precede colon in " + "assumed size array specification at %C"); + return AS_UNKNOWN; + } + if (gfc_match_char (':') == MATCH_YES) return AS_DEFERRED; @@ -591,6 +599,8 @@ gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim) { as->rank++; current_type = match_array_element_spec (as); + if (current_type == AS_UNKNOWN) + goto cleanup; /* Note that current_type == AS_ASSUMED_SIZE for both assumed-size and implied-shape specifications. If the rank is at least 2, we can @@ -600,8 +610,6 @@ gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim) if (as->rank == 1) { - if (current_type == AS_UNKNOWN) - goto cleanup; as->type = current_type; } else diff --git a/gcc/testsuite/gfortran.dg/pr102180.f90 b/gcc/testsuite/gfortran.dg/pr102180.f90 new file mode 100644 index 00000000000..cbf3e7299e7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102180.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-fcoarray=lib" } +! PR fortran/102180 - Improve checking of assumed size array spec + +subroutine s(x,y) + real :: x(0:*) ! legal + real :: y[0:*] ! legal +end + +subroutine t(x,y) + real :: x(:*) ! { dg-error "A lower bound must precede colon" } + real :: y[:*] ! { dg-error "A lower bound must precede colon" } +end + +subroutine u(x,y,z) + real :: x(2,*) + real :: y(2,2:*) + real :: z(2,:*) ! { dg-error "A lower bound must precede colon" } +end -- 2.35.3