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-10505] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209]
Date: Sat,  4 Feb 2023 15:43:32 +0000 (GMT)	[thread overview]
Message-ID: <20230204154332.9FE4C3861C40@sourceware.org> (raw)

https://gcc.gnu.org/g:8e58d94ac56127ebca3a893284455032a707d948

commit r11-10505-g8e58d94ac56127ebca3a893284455032a707d948
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Jul 14 22:24:55 2022 +0200

    Fortran: error recovery for bad initializers of implied-shape arrays [PR106209]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/106209
            * decl.c (add_init_expr_to_sym): Handle bad initializers for
            implied-shape arrays.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/106209
            * gfortran.dg/pr106209.f90: New test.
    
    Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
    (cherry picked from commit 748f8a8b145dde59c7b63aa68b5a59515b7efc49)

Diff:
---
 gcc/fortran/decl.c                     | 15 +++++++++++++--
 gcc/testsuite/gfortran.dg/pr106209.f90 |  9 +++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index c25b53f9772..6eb39d36196 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -2050,10 +2050,21 @@ add_init_expr_to_sym (const char *name, gfc_expr **initp, locus *var_locus)
 	  /* The shape may be NULL for EXPR_ARRAY, set it.  */
 	  if (init->shape == NULL)
 	    {
-	      gcc_assert (init->expr_type == EXPR_ARRAY);
+	      if (init->expr_type != EXPR_ARRAY)
+		{
+		  gfc_error ("Bad shape of initializer at %L", &init->where);
+		  return false;
+		}
+
 	      init->shape = gfc_get_shape (1);
 	      if (!gfc_array_size (init, &init->shape[0]))
-		  gfc_internal_error ("gfc_array_size failed");
+		{
+		  gfc_error ("Cannot determine shape of initializer at %L",
+			     &init->where);
+		  free (init->shape);
+		  init->shape = NULL;
+		  return false;
+		}
 	    }
 
 	  for (dim = 0; dim < sym->as->rank; ++dim)
diff --git a/gcc/testsuite/gfortran.dg/pr106209.f90 b/gcc/testsuite/gfortran.dg/pr106209.f90
new file mode 100644
index 00000000000..44f9233ec2f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr106209.f90
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/106209 - ICE in add_init_expr_to_sym
+! Contributed by G.Steinmetz
+
+program p
+  integer, parameter :: a(:) = 0   ! { dg-error "of deferred shape" }
+  integer, parameter :: b(*) = a   ! { dg-error "Bad shape of initializer" }
+  integer, parameter :: c(*) = [a] ! { dg-error "Cannot determine shape" }
+end

                 reply	other threads:[~2023-02-04 15:43 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=20230204154332.9FE4C3861C40@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).