diff mbox series

PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355

Message ID trinity-04722592-8d85-45db-b454-3ee19fb10ad7-1630359621776@3c-app-gmx-bs11
State New
Headers show
Series PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355 | expand

Commit Message

Harald Anlauf Aug. 30, 2021, 9:40 p.m. UTC
There was an issue when trying to use an element from an array constructor
which was a broken in a way probably only Gerhard could conceive.
We hit an assert that can be replaced by more robust code.

Patch is basically Steve's.

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

Thanks,
Harald


Fortran - improve error recovery determining array element from constructor

gcc/fortran/ChangeLog:

	PR fortran/101327
	* expr.c (find_array_element): When bounds cannot be determined as
	constant, return error instead of aborting.

gcc/testsuite/ChangeLog:

	PR fortran/101327
	* gfortran.dg/pr101327.f90: New test.

Comments

Harald Anlauf Sept. 6, 2021, 7:32 p.m. UTC | #1
PING.

> Gesendet: Montag, 30. August 2021 um 23:40 Uhr
> Von: "Harald Anlauf" <anlauf@gmx.de>
> An: "fortran" <fortran@gcc.gnu.org>, "gcc-patches" <gcc-patches@gcc.gnu.org>
> Betreff: [PATCH] PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355
>
> There was an issue when trying to use an element from an array constructor
> which was a broken in a way probably only Gerhard could conceive.
> We hit an assert that can be replaced by more robust code.
>
> Patch is basically Steve's.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
>
> Thanks,
> Harald
>
>
> Fortran - improve error recovery determining array element from constructor
>
> gcc/fortran/ChangeLog:
>
> 	PR fortran/101327
> 	* expr.c (find_array_element): When bounds cannot be determined as
> 	constant, return error instead of aborting.
>
> gcc/testsuite/ChangeLog:
>
> 	PR fortran/101327
> 	* gfortran.dg/pr101327.f90: New test.
>
>
Tobias Burnus Sept. 7, 2021, 12:02 a.m. UTC | #2
On 30.08.21 23:40, Harald Anlauf via Fortran wrote:
> There was an issue when trying to use an element from an array constructor
> which was a broken in a way probably only Gerhard could conceive.
> We hit an assert that can be replaced by more robust code.
>
> Patch is basically Steve's.
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?

LGTM. Thanks to both of you – and sorry for the belated review.

Tobias

> Fortran - improve error recovery determining array element from constructor
>
> gcc/fortran/ChangeLog:
>
>       PR fortran/101327
>       * expr.c (find_array_element): When bounds cannot be determined as
>       constant, return error instead of aborting.
>
> gcc/testsuite/ChangeLog:
>
>       PR fortran/101327
>       * gfortran.dg/pr101327.f90: New test.
>
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
diff mbox series

Patch

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 35563a78697..dfecc3012e1 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1337,7 +1337,9 @@  find_array_element (gfc_constructor_base base, gfc_array_ref *ar,
   for (i = 0; i < ar->dimen; i++)
     {
       if (!gfc_reduce_init_expr (ar->as->lower[i])
-	  || !gfc_reduce_init_expr (ar->as->upper[i]))
+	  || !gfc_reduce_init_expr (ar->as->upper[i])
+	  || ar->as->upper[i]->expr_type != EXPR_CONSTANT
+	  || ar->as->lower[i]->expr_type != EXPR_CONSTANT)
 	{
 	  t = false;
 	  cons = NULL;
@@ -1351,9 +1353,6 @@  find_array_element (gfc_constructor_base base, gfc_array_ref *ar,
 	  goto depart;
 	}

-      gcc_assert (ar->as->upper[i]->expr_type == EXPR_CONSTANT
-		  && ar->as->lower[i]->expr_type == EXPR_CONSTANT);
-
       /* Check the bounds.  */
       if ((ar->as->upper[i]
 	   && mpz_cmp (e->value.integer,
diff --git a/gcc/testsuite/gfortran.dg/pr101327.f90 b/gcc/testsuite/gfortran.dg/pr101327.f90
new file mode 100644
index 00000000000..f4377aabe7a
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101327.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! PR fortran/101327 - ICE in find_array_element, at fortran/expr.c:1355
+
+subroutine s
+  integer, parameter :: n([2]) = [1, 2] ! { dg-error "must be scalar" }
+  type t
+     integer :: a(n(1):n(2))
+  end type
+end
+
+! { dg-error "cannot be automatic or of deferred shape" " " { target *-*-* } 5 }