]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fortran: Fix ICE in gfc_trans_create_temp_array for assumed-rank [PR100194]
authorChristopher Albert <albert@tugraz.at>
Tue, 31 Mar 2026 06:26:57 +0000 (08:26 +0200)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Wed, 1 Apr 2026 01:34:15 +0000 (18:34 -0700)
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>
gcc/fortran/trans-expr.cc
gcc/testsuite/gfortran.dg/pr100194.f90 [new file with mode: 0644]

index d5254be007d650416514a85f261246b64923d457..5291896158451f54494e490e21c03ccca969c48f 100644 (file)
@@ -7956,7 +7956,8 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym,
                       && (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,
diff --git a/gcc/testsuite/gfortran.dg/pr100194.f90 b/gcc/testsuite/gfortran.dg/pr100194.f90
new file mode 100644 (file)
index 0000000..a8066e1
--- /dev/null
@@ -0,0 +1,40 @@
+! { 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
+
+