From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: error recovery on invalid array reference of non-array [PR103590] Content-Type: multipart/mixed; boundary=abmob-81907186-88c5-4559-9c79-e6f6f9a2025b 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: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jul 2022 20:43:10 -0000 --abmob-81907186-88c5-4559-9c79-e6f6f9a2025b Content-Type: text/plain; charset=UTF-8 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 --abmob-81907186-88c5-4559-9c79-e6f6f9a2025b Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fortran-error-recovery-on-invalid-array-reference-of.patch Content-Transfer-Encoding: quoted-printable =46rom 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. =2D-- 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 =2D-- 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 =3D=3D 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 =3D as; as =3D NULL; @@ -5028,6 +5032,8 @@ find_array_spec (gfc_expr *e) if (as !=3D NULL) gfc_internal_error ("find_array_spec(): unused as(2)"); + + return true; } @@ -5346,7 +5352,8 @@ gfc_resolve_ref (gfc_expr *expr) for (ref =3D expr->ref; ref; ref =3D ref->next) if (ref->type =3D=3D REF_ARRAY && ref->u.ar.as =3D=3D 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/gf= ortran.dg/associate_54.f90 index 003175a47fd..b23a4f160ac 100644 =2D-- 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 =3D> obj%state(TEST_STATES)) ! { dg-error "is used a= s array" } ! state =3D a - state(TEST_STATE) =3D a + state(TEST_STATE) =3D a ! { dg-error "has not been declared as an a= rray" } end associate end subroutine test_alter_state1 end module test - diff --git a/gcc/testsuite/gfortran.dg/associate_59.f90 b/gcc/testsuite/gf= ortran.dg/associate_59.f90 new file mode 100644 index 00000000000..2da97731d39 =2D-- /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 =3D> 1) + print *, [character(a(1)) :: '1'] ! { dg-error "Scalar INTEGER expres= sion" } + end associate +end =2D- 2.35.3 --abmob-81907186-88c5-4559-9c79-e6f6f9a2025b--