From patchwork Mon Jul 18 20:43:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 46 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp2066109eik; Mon, 18 Jul 2022 13:43:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsjiFXOsKyuC7S2YTfMMDuAsQ6hL+Ij4NdZn4Wc5mLQogEhaeAvJMq2Ctki4pUgZWIESJV X-Received: by 2002:a05:6402:150d:b0:43a:2cac:ca24 with SMTP id f13-20020a056402150d00b0043a2cacca24mr39532858edw.110.1658177032663; Mon, 18 Jul 2022 13:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658177032; cv=none; d=google.com; s=arc-20160816; b=Z+7GdlA5f2ZKIPz8yPECG1XbSdrsfony7Ry/FAI2p/eDvKrTQ5RutntHmV7sQE2KQJ niguhpp+c9V+Gzq6GpWe3h7dZx/HSBgf1ZKzawd7DNoaqW/WgeEUOYXNL5UeTfKEzf0O QNZYGS5FzcYpiuwSSPE9ErEhTLkqwMNyKUI0LMr5mmnZQtWp6olUJHUI5mugnp5gxfx5 pc607FGKldWvI+9pqntrUwKapHpArikt2QBPv+4E12zyufWZQIfK26oeN3rohMJo9k1q 7ryPFAwHxgLKnPtJKfD7XeApy315/jhIJi6AuW71QPk/7+RyQuV7M36+BFIbj7OBe+oJ NBLA== 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:sensitivity :importance:date:subject:to:message-id:mime-version:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=iXUDqE+uD56oRtMkoSk2FetOUVYZcfxfXoNvTaO4b8w=; b=eLNC0swc1t2Ka6u+yXBRu+xtZVKqQrzXFZvq2XaOZ+WJtJ6coEowYXYmvJUkObcL4Y 5Q1NVu5L+BMc9PUTLDBk0oacAMFRVk+8AmB8EdE20VofkR24ssNsZkVlInqtlDCxhvY0 VTsOS5idurn0oEJb1AsYSPytzueZaL43phgR0Cl/sTvQ+tzLVcgbqNBwpEndvZ1CCH/Z QmGqqOUbep2btKUpHVeUaC+TezY+LFGH/fAr8iazAKD2wV87ihzGohSZaXyh+n5xRNn2 h4X1Vjc8VSqDsETAdRSKADwKzzLhBuJAKyHHWeXqE/tNONORLL8pqkpV/CBbhDhh5Zy6 5egQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fZ4KMsoT; 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 jv13-20020a170907768d00b007262b057924si12590045ejc.900.2022.07.18.13.43.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 13:43:52 -0700 (PDT) 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=fZ4KMsoT; 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 708063852761 for ; Mon, 18 Jul 2022 20:43:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 708063852761 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658177031; bh=iXUDqE+uD56oRtMkoSk2FetOUVYZcfxfXoNvTaO4b8w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fZ4KMsoTmMheemC/FYNluqwHOV77PSpamcks9Te6GwdGqN3O31h+jMk3Ir/m+Cyoc s6Z6BXM3lOeDRuLzGG4XoEKtQKo7zexmTo88h9FhIffyoNsNQQGNN643jdmDkSgpwO plNtMK3lK7bh6JSe4PREmANJF0y0G1Ko3LbZX2Fo= 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.20]) by sourceware.org (Postfix) with ESMTPS id 2F9A73858D39; Mon, 18 Jul 2022 20:43:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2F9A73858D39 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.26] ([93.207.82.26]) by web-mail.gmx.net (3c-app-gmx-bap07.server.lan [172.19.172.77]) (via HTTP); Mon, 18 Jul 2022 22:43:04 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery on invalid array reference of non-array [PR103590] Date: Mon, 18 Jul 2022 22:43:04 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:ZfhkRPjIspI9cuWTDA3xnihdP9xvO4KuiNpovXFFCCZeNQNXTJuFzoKRwkbq7tg6s/869 NTPD9VYthNfn7Yup1cVO117gI+fXJ66HUE7BMAMJegXUAn8ToMMuZhN3EMaGVcNAfpAz1PEJay3N JEPz5YwHMZMfehSHSg8yqVNtK2C0gsEmC+J8ZZP+Vw7EYYULXTXRlaCyUJu92aas+WTxVWw1Ir56 8ojveEtJXquWleUYFBUpcyMweft73ElIxLuuH7bBqv7W3id65QpXLnpkW7buAs72T0T94EJgJYzh +A= X-UI-Out-Filterresults: notjunk:1;V03:K0:Zhi4dl4F0hs=:Dt9W2UWgaUeJ3E03WXaR5b J/lkpan6S6ewheD6QJMV8JJwyD/nLpkrQeC8OkBqwaq4suye0MCW+qKCX1+r1Mebf8PdWRQwS m5KAx1Zz4efXr7LUC68pJ6xYK3DLwykCGli8LA7jQbhFY8YthriFuVQYIntxvvut1LNyrx1ZF avLeF93+gYv8Fg98O8efPC6rjuzqoZwdoBCeMkVVBfwd5tceX69eFrlfWSAbawfK9et9zItze wSJzY+A2wu20VUfuPTGp7ySGusiVk1h7IYRSkihfgKz6xFdfyA/QC0nbM9SDOIqZbOsaKs0B4 vFANmtCvaa4kXIvbMi9/KZSgZ2sE++MGpkWv45izjX+NIo7BqWUBkxbkDeSX2ieKDDTt+YYbI wweebfGgyo7Ra1uJtK2bnWuJnUtbtdOdbB7aBxgkZFSGBfbiNoQccz/N4BcwD8IvACQ1GT2w8 bS5Sz/m8OMn1EOrNpXvClL19ET+wNz7zGXIrJkKv8iKz0+BMxZJwp4mB+OWx3RaxIBzhP1Tgb mPD1ONPmHa4gGPbZj+tEg8TIv6y8CBcClNytKj0hRZuATtCi/73VJMcIWdfvmn5la3pKNjo2K jPrd8Eb/kR22fxjgGIzthm4PwXdpehUXuy7QGCJvlEI9nltiMG4zr9LGalrNnBfG/rQuJRzts 1usoSLJ9L42ICD0ahkM4RY3gpTLpjxXL3JsTcn4DefWhTtojrsN3aVaeJf3u9r06+i1jEAvWc 5t0CoYV2F8efygKEphcBv5xqt+SOAr/u/o7Q7mEJyCZ2NmRE4GNHHR5aH3NnTX72qAsUSIk+L Ni+xypI X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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: "Li, Pan2 via Gcc-patches" 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?1738724639784305801?= X-GMAIL-MSGID: =?utf-8?q?1738724639784305801?= Dear all, I intend to commit the attached patch as obvious to mainline within the next 24h unless someone complains. It replaces a lazy gfc_internal_error by an explicit error message and an error recovery path. As a side-effect, we now diagnose a previously missed error in testcase gfortran.dg/associate_54.f90 similarly to Intel. Regtested on x86_64-pc-linux-gnu. Thanks, Harald From e6ecc4d8227afea565b0555e95a4f5dcb8f4ecab Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 18 Jul 2022 22:34:53 +0200 Subject: [PATCH] Fortran: error recovery on invalid array reference of non-array [PR103590] gcc/fortran/ChangeLog: PR fortran/103590 * resolve.cc (find_array_spec): Change function result to bool to enable error recovery. Generate error message for missing array spec instead of an internal error. (gfc_resolve_ref): Use function result from find_array_spec for error recovery. gcc/testsuite/ChangeLog: PR fortran/103590 * gfortran.dg/associate_54.f90: Adjust. * gfortran.dg/associate_59.f90: New test. --- gcc/fortran/resolve.cc | 13 ++++++++++--- gcc/testsuite/gfortran.dg/associate_54.f90 | 3 +-- gcc/testsuite/gfortran.dg/associate_59.f90 | 9 +++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/associate_59.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 2ebf076f730..dacd33561d0 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -4976,7 +4976,7 @@ gfc_resolve_dim_arg (gfc_expr *dim) static void resolve_assoc_var (gfc_symbol* sym, bool resolve_target); -static void +static bool find_array_spec (gfc_expr *e) { gfc_array_spec *as; @@ -5004,7 +5004,11 @@ find_array_spec (gfc_expr *e) { case REF_ARRAY: if (as == NULL) - gfc_internal_error ("find_array_spec(): Missing spec"); + { + gfc_error ("Symbol %qs at %L has not been declared as an array", + e->symtree->n.sym->name, &e->where); + return false; + } ref->u.ar.as = as; as = NULL; @@ -5028,6 +5032,8 @@ find_array_spec (gfc_expr *e) if (as != NULL) gfc_internal_error ("find_array_spec(): unused as(2)"); + + return true; } @@ -5346,7 +5352,8 @@ gfc_resolve_ref (gfc_expr *expr) for (ref = expr->ref; ref; ref = ref->next) if (ref->type == REF_ARRAY && ref->u.ar.as == NULL) { - find_array_spec (expr); + if (!find_array_spec (expr)) + return false; break; } diff --git a/gcc/testsuite/gfortran.dg/associate_54.f90 b/gcc/testsuite/gfortran.dg/associate_54.f90 index 003175a47fd..b23a4f160ac 100644 --- a/gcc/testsuite/gfortran.dg/associate_54.f90 +++ b/gcc/testsuite/gfortran.dg/associate_54.f90 @@ -26,9 +26,8 @@ contains integer, intent(in) :: a associate (state => obj%state(TEST_STATES)) ! { dg-error "is used as array" } ! state = a - state(TEST_STATE) = a + state(TEST_STATE) = a ! { dg-error "has not been declared as an array" } end associate end subroutine test_alter_state1 end module test - diff --git a/gcc/testsuite/gfortran.dg/associate_59.f90 b/gcc/testsuite/gfortran.dg/associate_59.f90 new file mode 100644 index 00000000000..2da97731d39 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/associate_59.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/103590 - ICE: find_array_spec(): Missing spec +! Contributed by G.Steinmetz + +program p + associate (a => 1) + print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER expression" } + end associate +end -- 2.35.3