public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209]
@ 2022-07-14 20:34 Harald Anlauf
  2022-07-15  1:46 ` Jerry D
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-07-14 20:34 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Dear all,

the attached patch introduces error recovery for two cases of using
an invalid array in a declaration of an implied-shape array instead
of hitting internal errors.

Initial patch by Steve.  The final version was approved in the PR
by Steve.

Committed as:

https://gcc.gnu.org/g:748f8a8b145dde59c7b63aa68b5a59515b7efc49

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr106209.patch --]
[-- Type: text/x-patch, Size: 2284 bytes --]

From 748f8a8b145dde59c7b63aa68b5a59515b7efc49 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 14 Jul 2022 22:24:55 +0200
Subject: [PATCH] Fortran: error recovery for bad initializers of implied-shape
 arrays [PR106209]

gcc/fortran/ChangeLog:

	PR fortran/106209
	* decl.cc (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>
---
 gcc/fortran/decl.cc                    | 15 +++++++++++++--
 gcc/testsuite/gfortran.dg/pr106209.f90 |  9 +++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr106209.f90

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 339f8b15035..b6400514731 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -2129,10 +2129,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
--
2.35.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, committed] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209]
  2022-07-14 20:34 [PATCH, committed] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209] Harald Anlauf
@ 2022-07-15  1:46 ` Jerry D
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry D @ 2022-07-15  1:46 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches


Hi Herald,

Looks good to me. I have always preferred informative messages.

Thanks,

Jerry
On 7/14/22 1:34 PM, Harald Anlauf via Fortran wrote:
> Dear all,
>
> the attached patch introduces error recovery for two cases of using
> an invalid array in a declaration of an implied-shape array instead
> of hitting internal errors.
>
> Initial patch by Steve.  The final version was approved in the PR
> by Steve.
>
> Committed as:
>
> https://gcc.gnu.org/g:748f8a8b145dde59c7b63aa68b5a59515b7efc49
>
> Thanks,
> Harald
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-15  1:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14 20:34 [PATCH, committed] Fortran: error recovery for bad initializers of implied-shape arrays [PR106209] Harald Anlauf
2022-07-15  1:46 ` Jerry D

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).