public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103588 - ICE: Simplification error in gfc_ref_dimen_size, at fortran/array.c:2407
@ 2021-12-06 22:39 Harald Anlauf
  2021-12-07 12:29 ` Mikael Morin
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-12-06 22:39 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

using a bad expression as stride in a subsequent array section did
lead to an internal error which was directly invoked after the
failure.  We better return a failure code to let error recovery
do its expected job.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-catch-failed-simplification-of-bad-stride-ex.patch --]
[-- Type: text/x-patch, Size: 2011 bytes --]

From 1487d327b13b45acca79c0c691a748ca1a50bc04 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Mon, 6 Dec 2021 23:34:17 +0100
Subject: [PATCH] Fortran: catch failed simplification of	bad stride
 expression

gcc/fortran/ChangeLog:

	PR fortran/103588
	* array.c (gfc_ref_dimen_size): Do not generate internal error on
	failed simplification of stride expression; just return failure.

gcc/testsuite/ChangeLog:

	PR fortran/103588
	* gfortran.dg/pr103588.f90: New test.
---
 gcc/fortran/array.c                    | 8 +++-----
 gcc/testsuite/gfortran.dg/pr103588.f90 | 8 ++++++++
 2 files changed, 11 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103588.f90

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 5762c8d92d4..5f9ed17f919 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -2403,11 +2403,9 @@ gfc_ref_dimen_size (gfc_array_ref *ar, int dimen, mpz_t *result, mpz_t *end)
 	{
 	  stride_expr = gfc_copy_expr(ar->stride[dimen]);

-	  if(!gfc_simplify_expr(stride_expr, 1))
-	    gfc_internal_error("Simplification error");
-
-	  if (stride_expr->expr_type != EXPR_CONSTANT
-	      || mpz_cmp_ui (stride_expr->value.integer, 0) == 0)
+	  if (!gfc_simplify_expr (stride_expr, 1)
+	     || stride_expr->expr_type != EXPR_CONSTANT
+	     || mpz_cmp_ui (stride_expr->value.integer, 0) == 0)
 	    {
 	      mpz_clear (stride);
 	      return false;
diff --git a/gcc/testsuite/gfortran.dg/pr103588.f90 b/gcc/testsuite/gfortran.dg/pr103588.f90
new file mode 100644
index 00000000000..198e1766cd2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103588.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR fortran/103588 - ICE: Simplification error in gfc_ref_dimen_size
+! Contributed by G.Steinmetz
+
+program p
+  integer, parameter :: a(:) = [1,2] ! { dg-error "cannot be automatic or of deferred shape" }
+  integer :: b(2) = a(::a(1))        ! { dg-error "Invalid" }
+end
--
2.26.2


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

* Re: [PATCH] PR fortran/103588 - ICE: Simplification error in gfc_ref_dimen_size, at fortran/array.c:2407
  2021-12-06 22:39 [PATCH] PR fortran/103588 - ICE: Simplification error in gfc_ref_dimen_size, at fortran/array.c:2407 Harald Anlauf
@ 2021-12-07 12:29 ` Mikael Morin
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Morin @ 2021-12-07 12:29 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

Hello,

On 06/12/2021 23:39, Harald Anlauf via Fortran wrote:
> diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
> index 5762c8d92d4..5f9ed17f919 100644
> --- a/gcc/fortran/array.c
> +++ b/gcc/fortran/array.c
> @@ -2403,11 +2403,9 @@ gfc_ref_dimen_size (gfc_array_ref *ar, int dimen, mpz_t *result, mpz_t *end)
>  	{
>  	  stride_expr = gfc_copy_expr(ar->stride[dimen]);
> 
> -	  if(!gfc_simplify_expr(stride_expr, 1))
> -	    gfc_internal_error("Simplification error");
> -
> -	  if (stride_expr->expr_type != EXPR_CONSTANT
> -	      || mpz_cmp_ui (stride_expr->value.integer, 0) == 0)
> +	  if (!gfc_simplify_expr (stride_expr, 1)
> +	     || stride_expr->expr_type != EXPR_CONSTANT
> +	     || mpz_cmp_ui (stride_expr->value.integer, 0) == 0)
>  	    {
>  	      mpz_clear (stride);
>  	      return false;

it’s a preexisting problem, but stride_expr should be freed before 
returning false above.

OK with that change.

Thanks.

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

end of thread, other threads:[~2021-12-07 12:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-06 22:39 [PATCH] PR fortran/103588 - ICE: Simplification error in gfc_ref_dimen_size, at fortran/array.c:2407 Harald Anlauf
2021-12-07 12:29 ` Mikael Morin

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