https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93835
markeggleston at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |markeggleston at gcc dot gnu.org --- Comment #4 from markeggleston at gcc dot gnu.org --- After applying the patch in comment 2 the ICE no longer occurs, however, it reveals an error when using the shape intrinsic with the findloc intrinsic. program test print *, findloc(shape([1, 2, 3, 4]), 4) end program produces: 0 i.e. 4 is not found in the array returned by shape. shape does indeed return [ 4 ] but the expression representing the array does not have a shape defined. This is why it is necessary to check for the existence of shape in the original patch. Adding a shape to the result expression addressed the issue and also means that the original is not required: diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 613fdafd1a6..59afb239af5 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -7228,6 +7228,8 @@ gfc_simplify_shape (gfc_expr *source, gfc_expr *kind) return NULL; result = gfc_get_array_expr (BT_INTEGER, k, &source->where); + result->shape = gfc_get_shape (1); + mpz_init (result->shape[0]); if (source->rank == 0) return result; @@ -7284,6 +7286,8 @@ gfc_simplify_shape (gfc_expr *source, gfc_expr *kind) if (t) gfc_clear_shape (shape, source->rank); + mpz_set_si (result->shape[0], source->rank); + return result; } There is some tidying up to do as pr77351.f90 now produces one error instead of two: 4 | print *, any(shape(z) /= [4,1]) ! { dg-error "shape for elemental binary" } | 1 2 Error: Shapes for operands at (1) and (2) are not conformable verses: 4 | print *, any(shape(z) /= [4,1]) ! { dg-error "shape for elemental binary" } | 1 Error: Different shape for elemental binary operation at (1) on dimension 1 (1 and 2) pr77351.f90:4:16: 4 | print *, any(shape(z) /= [4,1]) ! { dg-error "shape for elemental binary" } | 1 Error: Array operands are incommensurate at (1) Final patch in preparation.