public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-10281] Fortran: improve error recovery while simplifying size of bad array [PR103694]
Date: Fri, 30 Sep 2022 20:33:16 +0000 (GMT)	[thread overview]
Message-ID: <20220930203316.EB4E83858D1E@sourceware.org> (raw)

https://gcc.gnu.org/g:6a552015b9c4b2e029a47f44f1866578e3af5bd0

commit r11-10281-g6a552015b9c4b2e029a47f44f1866578e3af5bd0
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Aug 23 22:16:14 2022 +0200

    Fortran: improve error recovery while simplifying size of bad array [PR103694]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/103694
            * simplify.c (simplify_size): The size expression of an array cannot
            be simplified if an error occurs while resolving the array spec.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/103694
            * gfortran.dg/pr103694.f90: New test.
    
    (cherry picked from commit 55d8c5409325001c89c35c3d04d425dec9127146)

Diff:
---
 gcc/fortran/simplify.c                 |  5 +++--
 gcc/testsuite/gfortran.dg/pr103694.f90 | 11 +++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index a1834e33081..3b033a6be92 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -7488,8 +7488,9 @@ simplify_size (gfc_expr *array, gfc_expr *dim, int k)
     }
 
   for (ref = array->ref; ref; ref = ref->next)
-    if (ref->type == REF_ARRAY && ref->u.ar.as)
-      gfc_resolve_array_spec (ref->u.ar.as, 0);
+    if (ref->type == REF_ARRAY && ref->u.ar.as
+	&& !gfc_resolve_array_spec (ref->u.ar.as, 0))
+      return NULL;
 
   if (dim == NULL)
     {
diff --git a/gcc/testsuite/gfortran.dg/pr103694.f90 b/gcc/testsuite/gfortran.dg/pr103694.f90
new file mode 100644
index 00000000000..3ed8b2088da
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103694.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/103694 - ICE in gfc_conv_expr_op
+! Contributed by G.Steinmetz
+
+subroutine s
+  type t
+     integer :: a(2)
+  end type
+  type(t) :: x((0.)/0)
+  integer :: n = size(x(1)%a) ! { dg-error "does not reduce to a constant expression" }
+end

                 reply	other threads:[~2022-09-30 20:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220930203316.EB4E83858D1E@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).