https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104350
anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1 Last reconfirmed| |2022-02-25 --- Comment #1 from anlauf at gcc dot gnu.org --- Confirmed. There are multiple ways to avoid the ICE: - replace gfc_internal_error in gfc_array_dimen_size by gfc_error, e.g. diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index f1d92e00c98..a42fb8f59fe 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "options.h" #include "gfortran.h" #include "parse.h" +#include "intrinsic.h" #include "match.h" #include "constructor.h" @@ -2571,7 +2572,13 @@ gfc_array_dimen_size (gfc_expr *array, int dimen, mpz_t *result) return false; if (dimen < 0 || dimen > array->rank - 1) - gfc_internal_error ("gfc_array_dimen_size(): Bad dimension"); + { + gfc_error ("DIM argument (%d) to intrinsic %qs at %L out of range " + "(1:%d)", dimen+1, gfc_current_intrinsic, + gfc_current_intrinsic_where, array->rank); + return false; + } +// gfc_internal_error ("gfc_array_dimen_size(): Bad dimension"); switch (array->expr_type) { This however produces two error messages of the kind: pr104350-z1.f90:4:21: 4 | print *, product([(size(x, dim=k), k=0,rank(x))]) | 1 Error: DIM argument (0) to intrinsic 'size' at (1) out of range (1:1) pr104350-z1.f90:4:10: 4 | print *, product([(size(x, dim=k), k=0,rank(x))]) | 1 Error: DIM argument (0) to intrinsic 'product' at (1) out of range (1:1) The second error is misleading. :-( - a similar patch to simplify_size generates a similar error twice. :-(