diff mbox series

PR fortran/95372 - ICE in find_array_section, at fortran/expr.c:1687

Message ID trinity-3b53cd61-091a-4e87-b574-cc7133f596b2-1607898430305@3c-app-gmx-bs68
State New
Headers show
Series PR fortran/95372 - ICE in find_array_section, at fortran/expr.c:1687 | expand

Commit Message

Harald Anlauf Dec. 13, 2020, 10:27 p.m. UTC
ICE on valid code.

Original patch by Steve, slightly adjusted and regtested on x86_64-pc-linux-gnu.

OK for master?  Backports?  Should be safe everywhere, as it replaces an assert
by an if condition.

Thanks,
Harald


PR fortran/95372 - ICE in find_array_section, at fortran/expr.c:1687

Fix handling of array references in array constructors.

gcc/fortran/ChangeLog:

	PR fortran/95372
	* expr.c (find_array_section): Replace assert into a conditional
	construct.

gcc/testsuite/ChangeLog:

	PR fortran/95372
	* gfortran.dg/pr95372.f90: New test.
diff mbox series

Patch

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index ae9b0a79474..4b0ca453968 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1684,9 +1684,11 @@  find_array_section (gfc_expr *expr, gfc_ref *ref)
 	}

       cons = gfc_constructor_lookup (base, limit);
-      gcc_assert (cons);
-      gfc_constructor_append_expr (&expr->value.constructor,
-				   gfc_copy_expr (cons->expr), NULL);
+      if (cons)
+	gfc_constructor_append_expr (&expr->value.constructor,
+				     gfc_copy_expr (cons->expr), NULL);
+      else
+	t = false;
     }

   mpz_clear (ptr);
diff --git a/gcc/testsuite/gfortran.dg/pr95372.f90 b/gcc/testsuite/gfortran.dg/pr95372.f90
new file mode 100644
index 00000000000..bedd2117c25
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95372.f90
@@ -0,0 +1,14 @@ 
+! PR fortran/95372 - ICE in find_array_section, at fortran/expr.c:1687
+
+program p
+  type t
+     integer :: a = 1
+  end type t
+  type(t), parameter :: x(3) = t()
+  type(t)            :: u(3) = t()
+  type(t)            :: y(1), v(1)
+  y = [x(2:2)]
+  v = [u(2:2)]
+  if (any (y% a /= 1)) stop 1
+  if (any (v% a /= 1)) stop 2
+end