]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: improve error recovery on bad array section
authorHarald Anlauf <anlauf@gmx.de>
Thu, 10 Feb 2022 20:22:48 +0000 (21:22 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Mon, 14 Feb 2022 19:31:14 +0000 (20:31 +0100)
gcc/fortran/ChangeLog:

PR fortran/104211
* expr.cc (find_array_section): Replace assertion by error
recovery when encountering bad array constructor.

gcc/testsuite/ChangeLog:

PR fortran/104211
* gfortran.dg/pr104211.f90: New test.

gcc/fortran/expr.cc
gcc/testsuite/gfortran.dg/pr104211.f90 [new file with mode: 0644]

index ed82a94022f2f3bbe6a2a3dae32341dcf7d8d564..c9c0ba4cc2ec6e762bcabd2bfdcad2446be74312 100644 (file)
@@ -1718,7 +1718,13 @@ find_array_section (gfc_expr *expr, gfc_ref *ref)
        }
 
       cons = gfc_constructor_lookup (base, limit);
-      gcc_assert (cons);
+      if (cons == NULL)
+       {
+         gfc_error ("Error in array constructor referenced at %L",
+                    &ref->u.ar.where);
+         t = false;
+         goto cleanup;
+       }
       gfc_constructor_append_expr (&expr->value.constructor,
                                   gfc_copy_expr (cons->expr), NULL);
     }
diff --git a/gcc/testsuite/gfortran.dg/pr104211.f90 b/gcc/testsuite/gfortran.dg/pr104211.f90
new file mode 100644 (file)
index 0000000..21b0a26
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/104211 - ICE in find_array_section
+! Contributed by G.Steinmetz
+
+program p
+  type t
+     real :: n
+  end type
+  type(t), parameter :: a(3) = [t(2)] ! { dg-error "Different shape" }
+  type(t), parameter :: b(2) = a(2:3) ! { dg-error "Error in array constructor" }
+end