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 6A9A63855024; Thu, 22 Jul 2021 19:03:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A9A63855024 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.9.160] ([79.251.9.160]) by web-mail.gmx.net (3c-app-gmx-bap16.server.lan [172.19.172.86]) (via HTTP); Thu, 22 Jul 2021 21:03:54 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: Tobias Burnus Cc: fortran , gcc-patches Subject: Re: [PATCH] PR fortran/101536 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:7324 Content-Type: multipart/mixed; boundary=kenitram-01f526f9-44ad-400f-be6e-0b47dd0b461c Date: Thu, 22 Jul 2021 21:03:54 +0200 Importance: normal Sensitivity: Normal In-Reply-To: References: X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:jGblwVan6ZixuQN6VK0rh/yLRQlPmkc33UNlOwYLID45UTvC1/LMsnGtTmae0wdsNUqGY M0nXaUmojHU9T6QeDvFpVRjW7MXawNpbLuhx/e0h9NBGtpR7bERcUDJ5wDT9IJR20cJH3lM9arcj xJ6uHBaLRcSCEK3j5aZDJFUbL2PrfsINLtptPeA7RDR3axTAyf3eY9nyKe0O4osbKrmkvA0N61N0 Z3L+kaW1mzZjjwPjbh9cftWlrdxS65FiOHLXa97h7YHl58ks/FpJSrvZG5SYgn/BATZJwmzzwbmd s8= X-UI-Out-Filterresults: notjunk:1;V03:K0:zEQSOS6sEi4=:5+YbjOe0/HENXbyVJQ33nD B40S0iBdeqS78NheRS70SoL8IVuAIeLDaUKXFtqUEv146kAI2zoCW9tY+5wx8plgkR56XcWvm rdJNOYdanm/VwZje1k9pUkg2jWoJbgWd4guzo35lN2TLLixFoxs4CRlhPJVJU+Y2qEjr4Yl8Z SNvqc6zj2sVhVq77NzLjTm0uVRGwqLhYxdeGiOuacWpgxZtRIN4abz/gLLGQS7VWiaX0b9rnC gzRCHml01Ze3mjWSCFQ5kptA4RjVwU6xNX+11CDkjxVAtjAFpOicwoK3zCcs+ZrhAPzg1Omq5 z7/xXquIeWc6aNR0Q2WCWpGFmULhAMsrFwWQdWbi+B1r90PoschM+Y7a9RPgFYJF6CTYEt0im xttFe1rPq8xmwZXOo36onTSe9Ix5tvPpiatAXFFNkix0ZqQnyWxrn5UntvOIfoMEHZkuC9n0Y ihhJ8ixIJyuAhAfW3z92twvyu3dALZ/4VyBYWZIgdVRYHy9C3i39CV74ArL6CRsaFaWSC/qRf ZERldldVr3jxwyxrHMu/C0AVB7X9DhJz8inWy+fylLb1iZ20sM8eqixI9exYp4TdhT1KlOWRa yKI74m7UQJ/7rxDDf0AJesqaPUHCJNT+PyVoEmbUDFc7vDMpPZJPvvUL4Y/H3eT0N2wkr4WDx fipR7cKzWsnQUrQHEj08KL9a772JSU0We3q+qaZ1Yu3D9dqBWp9d4dssmlIlfSBUwSiQhYVrN 7A68/oaqvuXB44p70jw+CUjj3g0gUWnZrluzTDdnS6Txrvv3zTXCpvzbgx0qymvkRAFh2y1l0 dkjTdHM3Fvyw9pCW4Snz218zIYy3A== X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, KAM_NUMSUBJECT, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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-List-Received-Date: Thu, 22 Jul 2021 19:04:01 -0000 --kenitram-01f526f9-44ad-400f-be6e-0b47dd0b461c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Tobias, you are right in that I was barking up the wrong tree. I was focussed too much on the testcase in the PR. > I think that one is wrong. While CLASS_DATA (e) accesses e->ts.u.derived= ->components, > which always works, your code assumes that there is only 'c' and not 'x%= c' where > 'c' is of type BT_CLASS and 'x' is of type BT_DERIVED. > > I wonder whether it works if you simply remove 'return true;' > as gfc_add_class_array_ref sets 'e->rank =3D CLASS(e)->rank (and > adds an AR_FULL ref, if needed). In the nonerror case, the > 'return true' is obtained via: > if (e->rank !=3D 0 && e->ts.type !=3D BT_PROCEDURE) > return true; > And, otherwise, it falls through to the error. > > OK if that works Well, I tried and this does not work. However, an additional plain check on e->rank !=3D 0 also in the CLASS cases fixes the original issue as well as your example: > type t > class(*), allocatable :: c(:) > end type t > type(t) :: x > x%c =3D [1,2,3,4] > print *, size(x%c) > print *, size(x%c(1)) ! { dg-error ... } > end And regtests ok. :-) See attached updated patch. Anything else I am missing? Thanks for the constructive review! Harald --kenitram-01f526f9-44ad-400f-be6e-0b47dd0b461c Content-Type: application/octet-stream Content-Disposition: attachment; filename=pr101536.patch-v2 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 27bf3a7eafe..b03d322ad9c 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -731,7 +731,7 @@ logical_array_check (gfc_expr *array, int n) static bool array_check (gfc_expr *e, int n) { - if (e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok + if (e->rank != 0 && e->ts.type == BT_CLASS && gfc_expr_attr (e).class_ok && CLASS_DATA (e)->attr.dimension && CLASS_DATA (e)->as->rank) { diff --git a/gcc/testsuite/gfortran.dg/pr101536.f90 b/gcc/testsuite/gfortran.dg/pr101536.f90 new file mode 100644 index 00000000000..f8fa1dee639 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr101536.f90 @@ -0,0 +1,26 @@ +! { dg-do compile } +! PR fortran/101536 - ICE in gfc_conv_expr_descriptor + +program p + type t + class(*), allocatable :: c(:) + end type t + type u + integer :: c(2) + end type + type(t) :: x + x%c = [1,2,3,4] + print *, size (x%c) + print *, size (x%c(1)) ! { dg-error "must be an array" } +contains + integer function f(x, y) + class(t), allocatable :: x(:) + class(u) :: y(:) + f = size (x) + f = size (x(1)) ! { dg-error "must be an array" } + f = size (y) + f = size (y%c(1)) + f = size (y(2)%c) + f = size (y(2)%c(1)) ! { dg-error "must be an array" } + end +end --kenitram-01f526f9-44ad-400f-be6e-0b47dd0b461c--