When a non-contiguous assumed-rank actual argument is passed to a
contiguous assumed-rank dummy, the compiler routes it through
gfc_conv_subref_array_arg which uses the scalarizer. The scalarizer
requires known rank at compile time, but assumed-rank arrays have
rank = -1, hitting gcc_assert (ss->dimen > 0).
Skip the scalarizer path for assumed-rank expressions and let them
fall through to gfc_conv_array_parameter, which handles assumed-rank
via the runtime pack/unpack functions.
gcc/fortran/ChangeLog:
PR fortran/100194
* trans-expr.cc (gfc_conv_procedure_call): Skip
gfc_conv_subref_array_arg for assumed-rank actual arguments
(e->rank == -1) when the dummy is contiguous.
gcc/testsuite/ChangeLog:
PR fortran/100194
* gfortran.dg/pr100194.f90: New test.
Signed-off-by: Christopher Albert <albert@tugraz.at>
&& (fsym->attr.target
? gfc_is_not_contiguous (e)
: !gfc_is_simply_contiguous (e, false, true))
- && gfc_expr_is_variable (e))
+ && gfc_expr_is_variable (e)
+ && e->rank != -1)
{
gfc_conv_subref_array_arg (&parmse, e, nodesc_arg,
fsym->attr.intent,
--- /dev/null
+! { dg-do compile }
+!
+! PR fortran/100194
+! ICE in gfc_trans_create_temp_array when passing a non-contiguous
+! assumed-rank array to a contiguous assumed-rank dummy argument.
+!
+! Contributed by Martin Diehl <m.diehl@kit.edu>
+
+subroutine s(x)
+ real :: x(..)
+ call t(x)
+contains
+ subroutine t(y)
+ real, contiguous :: y(..)
+ end
+end
+
+! The following from the PR, these compiled OK before the patch.
+!
+! Contributed by G. Steinmetz <gscfq@t-online.de>
+
+subroutine z3(x)
+ real, contiguous :: x(..)
+ call t(x)
+contains
+ subroutine t(y)
+ real, contiguous :: y(..)
+ end
+end
+
+subroutine z2(x)
+ real, contiguous :: x(..)
+ call t(x)
+contains
+ subroutine t(y)
+ real :: y(..)
+ end
+end
+
+