PR fortran/69419 - ICE: tree check: expected array_type, have real_type in gfc_conv_array_initializer, at fortran/trans-array.c:5618
Message ID | trinity-e29ae6f6-871e-4ad9-ba32-87892e503bb6-1635361763453@3c-app-gmx-bap04 |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A33993858405 for <patchwork@sourceware.org>; Wed, 27 Oct 2021 19:10:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A33993858405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635361811; bh=3nwTi40Z01itEfjLMx6RIWwu0TMBf4TN5cmxKeJr7A4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=x5iyZwZWSK+K3BpqxIP8NqnXK1ZfCQNxLU4MvjVHZoNGJnwzppMz+w0ax3ywpgevH aznh3N2geQi+UCGbKmZFql0xfu4T+MdsldPWmxqWCv79bpMZc9qPvZjCUQ8nqUalDB oJyykozr3i7HQv2shBg9UWbYqWri2WIYDSDfoib8= 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 E79923858402; Wed, 27 Oct 2021 19:09:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E79923858402 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.83.232] ([93.207.83.232]) by web-mail.gmx.net (3c-app-gmx-bap04.server.lan [172.19.172.74]) (via HTTP); Wed, 27 Oct 2021 21:09:23 +0200 MIME-Version: 1.0 Message-ID: <trinity-e29ae6f6-871e-4ad9-ba32-87892e503bb6-1635361763453@3c-app-gmx-bap04> To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org> Subject: [PATCH] PR fortran/69419 - ICE: tree check: expected array_type, have real_type in gfc_conv_array_initializer, at fortran/trans-array.c:5618 Content-Type: multipart/mixed; boundary=sgnirk-032ef4fc-18ad-4147-8662-0e9aa710f989 Date: Wed, 27 Oct 2021 21:09:23 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:tsiqLkLxkDwh2ykZyibsRhKqOPVW+m1F/aVZonCmkEHJBLplHMtEkvDauLR3DN7fHv2J4 6n+p6sGjcELMYqprOKhXk3eq3/o+2iAiCHiSanR+GRd0q1wUjiHaa6X9pc5CaCdnlbHRSUVJmu43 zRpKNNvT1fAfM/AOvIumooFfvmtdhgCl6dvUdFvwy3YajV5wl8oRNQ/gIYqdcshDc15vhNSnaX23 HELEi+XkTxQG0oLjFTHcsutTkMwZhjo1CtwZabPJlcK5Sna+ApZpMBnLTDvwcvPdef8Xlr7AcNPv 6A= X-UI-Out-Filterresults: notjunk:1;V03:K0:71EFnM3hl7g=:T6z/QnsLTEiBH/ZH4AOimz RTCDAqR8p6NIXUMOUaQCCd22k+y1cB77s2fqpJPs2PcQLDR54kkN5YXPsQNNg9kh5jEZLK6yH l4ZYQPbbHNoJx6O2o2E/dNe6vSVYec1EHQ0g8d5DTkLicRC0s0/H0/CT8IwsUZlKZppc/XNr3 DfuASQBhQCSujXMCorAbNWBw+mq50zOi96fjO7jT8yhJY/GzK0Xg1hHjq7EKI99c7Lrw6qR4p pQBmjpFQHzVB/CNELBY0eG1w8nTZ7AvpXHhpU6UfJHDUeA6Nu38xmCdgiFE6R7JFR90P2QuAw kmu9P5r8VJn95QRQnDZITD0bE6lAiuVr4gVoouVT+uJub4ukWXa1xMcO8es9drm+MeP/Tz43/ jQrozI7cuEISCVG2Led9lacpYBM5oW+rvGo6RYDtFThTxr1Q3gh7vPo1Vy2TMe89JWd26GTz6 HODs5xBoPxpE4rd7tUthIAmLAL3WybYujQIEiqGNhPe8pCxMUDcWFJV8zj88bNGAXQqZsWEFx /QX5AnNxdz/ams4hAPKL5/TD0GdWodFWUy2huor8KER1uGCVB9bVRpBV5VvnNB8XQnbv8/azu BROzWjeBfQAuFz3zr9uGFtNV+Hl4w8eLnMesvqFnG+3DP4g70UrLOfRY11OezrMqhr7ZiQNh2 kR8jfj7mnI4KD8yQwC54z4CaFYbnWzfkY3mlG8Gi2Iq5OlgoxoPab2tbWZ3ELnRMsrLnTuL2Y ncyyKsHe5UtukGE8Yuz5zZ5roQhQFioebO+NQbC900FZifcsFR+YzN6TwfKCsRw5VJYAdOQ3j AEtv+Op X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Harald Anlauf via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Harald Anlauf <anlauf@gmx.de> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
PR fortran/69419 - ICE: tree check: expected array_type, have real_type in gfc_conv_array_initializer, at fortran/trans-array.c:5618
|
|
Commit Message
Harald Anlauf
Oct. 27, 2021, 7:09 p.m. UTC
Dear Fortranners, when debugging the testcase, I noticed that a coarray declaration in a COMMON statement wrongly set the dimension attribute instead of the codimension. As a consequence, subsequent checks that catch this invalid situation would not trigger. I see two possible solutions: - in gfc_match_common, replace /* Deal with an optional array specification after the symbol name. */ m = gfc_match_array_spec (&as, true, true); by m = gfc_match_array_spec (&as, true, false); which in turn would lead to a syntax error. Interestingly, the Intel compiler also takes this route and gives a syntax error. - check the resulting as->corank and emit an error as in the attached patch. The attached patch regtests fine on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald
Comments
*PING* Am 27.10.21 um 21:09 schrieb Harald Anlauf via Fortran: > Dear Fortranners, > > when debugging the testcase, I noticed that a coarray declaration in > a COMMON statement wrongly set the dimension attribute instead of the > codimension. As a consequence, subsequent checks that catch this > invalid situation would not trigger. > > I see two possible solutions: > > - in gfc_match_common, replace > > /* Deal with an optional array specification after the > symbol name. */ > m = gfc_match_array_spec (&as, true, true); > > by > > m = gfc_match_array_spec (&as, true, false); > > which in turn would lead to a syntax error. Interestingly, the Intel > compiler also takes this route and gives a syntax error. > > - check the resulting as->corank and emit an error as in the attached > patch. > > The attached patch regtests fine on x86_64-pc-linux-gnu. OK for mainline? > > Thanks, > Harald >
On Wed, 3 Nov 2021 21:00:41 +0100 Harald Anlauf via Fortran <fortran@gcc.gnu.org> wrote: > *PING* > > Am 27.10.21 um 21:09 schrieb Harald Anlauf via Fortran: > > Dear Fortranners, > > > > when debugging the testcase, I noticed that a coarray declaration in > > a COMMON statement wrongly set the dimension attribute instead of the > > codimension. As a consequence, subsequent checks that catch this > > invalid situation would not trigger. > > > > I see two possible solutions: > > > > - in gfc_match_common, replace > > > > /* Deal with an optional array specification after the > > symbol name. */ > > m = gfc_match_array_spec (&as, true, true); If coarrays are generally forbidden in commons then.. > > > > by > > > > m = gfc_match_array_spec (&as, true, false); .. this sounds right to me. > > > > which in turn would lead to a syntax error. Interestingly, the Intel > > compiler also takes this route and gives a syntax error. > > > > - check the resulting as->corank and emit an error as in the attached > > patch. If we want to be more helpful than a mere syntax error (and we should be) then yes. Otherwise we'd have to explicitly @@ -5275,9 +5275,19 @@ gfc_match_common (void) /* Deal with an optional array specification after the symbol name. */ - m = gfc_match_array_spec (&as, true, true); + m = gfc_match_array_spec (&as, true, false); if (m == MATCH_ERROR) goto cleanup; + if (m == MATCH_NO) + { + /* See if it is a coarray and diagnose it nicely. */ + if (gfc_match_array_spec (&as, false, true) == MATCH_YES) + { + gfc_error ("Symbol %qs in COMMON at %C cannot be a " + "coarray", sym->name); + goto cleanup; + } + } where your patch works equally well and is more concise. Maybe you want to add a test for the double-colon variant too? common /c2/ y[:] ! { dg-error "cannot be a coarray" } A type with a coarray seems to require to be allocatable so is rejected (properly, but not mentioning the coarray) with Error: Derived type variable ‘comm_ty1’ in COMMON at (1) has an ultimate component that is allocatable When reading gfc_match_array_spec i thought that it might have been cleaner to split the coarray handling out to a separate gfc_match_coarray_spec but that's what we have. > > > > The attached patch regtests fine on x86_64-pc-linux-gnu. OK for mainline? LGTM but i cannot approve it. Thanks for the patch!
Hi Bernhard, Am 04.11.21 um 10:06 schrieb Bernhard Reutner-Fischer via Fortran: > On Wed, 3 Nov 2021 21:00:41 +0100 > Harald Anlauf via Fortran <fortran@gcc.gnu.org> wrote: > >> *PING* >> >> Am 27.10.21 um 21:09 schrieb Harald Anlauf via Fortran: >>> Dear Fortranners, >>> >>> when debugging the testcase, I noticed that a coarray declaration in >>> a COMMON statement wrongly set the dimension attribute instead of the >>> codimension. As a consequence, subsequent checks that catch this >>> invalid situation would not trigger. >>> >>> I see two possible solutions: >>> >>> - in gfc_match_common, replace >>> >>> /* Deal with an optional array specification after the >>> symbol name. */ >>> m = gfc_match_array_spec (&as, true, true); > > If coarrays are generally forbidden in commons then.. F2018: (R874) A common-block-object shall not be a dummy argument, a function result, an allocatable variable, a derived-type object with an ultimate component that is allocatable, a procedure pointer, an automatic data object, a variable with the BIND attribute, an unlimited polymorphic pointer, or a coarray. >>> >>> by >>> >>> m = gfc_match_array_spec (&as, true, false); > > .. this sounds right to me. > >>> >>> which in turn would lead to a syntax error. Interestingly, the Intel >>> compiler also takes this route and gives a syntax error. >>> >>> - check the resulting as->corank and emit an error as in the attached >>> patch. > > If we want to be more helpful than a mere syntax error (and we > should be) then yes. > Otherwise we'd have to explicitly > @@ -5275,9 +5275,19 @@ gfc_match_common (void) > > /* Deal with an optional array specification after the > symbol name. */ > - m = gfc_match_array_spec (&as, true, true); > + m = gfc_match_array_spec (&as, true, false); > if (m == MATCH_ERROR) > goto cleanup; > + if (m == MATCH_NO) > + { > + /* See if it is a coarray and diagnose it nicely. */ I think you would need to add gfc_array_spec *as; to avoid clobbering the correct "as" as it is needed later. > + if (gfc_match_array_spec (&as, false, true) == MATCH_YES) > + { > + gfc_error ("Symbol %qs in COMMON at %C cannot be a " > + "coarray", sym->name); > + goto cleanup; > + } > + } > > where your patch works equally well and is more concise. > Maybe you want to add a test for the double-colon variant too? > common /c2/ y[:] ! { dg-error "cannot be a coarray" } Well, that one is already rejected, although with a different error message. I am not sure whether to add that case. In fact, there are issues with not always rejecting things like y[:] in declarations as the last dimension must be "*" or "lbound:*". If checking gets improved in this direction, we would have to adjust the error message. So adding this variant now does not buy us much. > A type with a coarray seems to require to be allocatable so is > rejected (properly, but not mentioning the coarray) with > Error: Derived type variable ‘comm_ty1’ in COMMON at (1) has an ultimate component that is allocatable If multiple errors show up, which ones are most important or must show up? If you ask me, it is more important to get correct results from correct input than optimal error messages on wrong code. I guess users may have an opinion different from mine... > When reading gfc_match_array_spec i thought that it might have been cleaner > to split the coarray handling out to a separate gfc_match_coarray_spec but > that's what we have. >>> >>> The attached patch regtests fine on x86_64-pc-linux-gnu. OK for mainline? > > LGTM but i cannot approve it. > Thanks for the patch! > Thanks for your comments so far. Let's see what others think. Harald
Le 04/11/2021 à 20:49, Harald Anlauf via Fortran a écrit : > Let's see what others think. > OK, thanks. Mikael
Fortran: a symbol in a COMMON cannot be a coarray gcc/fortran/ChangeLog: PR fortran/69419 * match.c (gfc_match_common): Check array spec of a symbol in a COMMON object list and reject it if it is a coarray. gcc/testsuite/ChangeLog: PR fortran/69419 * gfortran.dg/pr69419.f90: New test. diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index 53a575e616e..df97620634d 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -5314,6 +5314,13 @@ gfc_match_common (void) goto cleanup; } + if (as->corank) + { + gfc_error ("Symbol %qs in COMMON at %C cannot be a " + "coarray", sym->name); + goto cleanup; + } + if (!gfc_add_dimension (&sym->attr, sym->name, NULL)) goto cleanup; diff --git a/gcc/testsuite/gfortran.dg/pr69419.f90 b/gcc/testsuite/gfortran.dg/pr69419.f90 new file mode 100644 index 00000000000..7329808611c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr69419.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! { dg-options "-fcoarray=lib" } +! PR fortran/69419 - ICE on invalid coarray in common + +blockdata b + real x ! { dg-error "must be in COMMON" } + common /c/ x[*] ! { dg-error "cannot be a coarray" } + data x /1.0/ +end