From: Harald Anlauf <anlauf@gmx.de>
To: Tobias Burnus <tobias@codesourcery.com>
Cc: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR fortran/101536 - ICE in gfc_conv_expr_descriptor, at fortran/trans-array.c:7324
Date: Thu, 22 Jul 2021 21:03:54 +0200 [thread overview]
Message-ID: <trinity-aae2adec-8a38-4393-b8c3-dc1536ba5ea6-1626980634539@3c-app-gmx-bap16> (raw)
In-Reply-To: <d5ce3f33-c84b-ab80-cf46-6f722e82d15a@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 1210 bytes --]
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 = CLASS(e)->rank (and
> adds an AR_FULL ref, if needed). In the nonerror case, the
> 'return true' is obtained via:
> if (e->rank != 0 && e->ts.type != 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 != 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 = [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
[-- Attachment #2: pr101536.patch-v2 --]
[-- Type: application/octet-stream, Size: 1324 bytes --]
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
next prev parent reply other threads:[~2021-07-22 19:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-21 20:22 Harald Anlauf
2021-07-22 16:47 ` Tobias Burnus
2021-07-22 19:03 ` Harald Anlauf [this message]
2021-07-23 7:58 ` Tobias Burnus
2021-07-23 19:08 ` Harald Anlauf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=trinity-aae2adec-8a38-4393-b8c3-dc1536ba5ea6-1626980634539@3c-app-gmx-bap16 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tobias@codesourcery.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).