https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97896
--- Comment #5 from anlauf at gcc dot gnu.org --- (In reply to Mikael Morin from comment #4) > Elemental actual arguments are some of those arrays involved. > Obviously one should not remove some of them in the middle of code > generation. > It should be done beforehand if at all. The problem is only the KIND argument, which must be a scalar constant that determines the function call and subsequent conversions. The patch below solves the issue in comment#0, as well as most of program p implicit none logical :: a(2) integer :: b(2) integer(8) :: d(2) b = index ('xyxyz','yx', back=a) b = index ('xyxyz','yx', back=a, kind=4) ! works now d = index ('xyxyz','yx', back=a, kind=8) ! works now ! b = index ('xyxyz','yx', back=a, kind=8) ! ICE remains ! d = index ('xyxyz','yx', back=a, kind=4) ! ICE remains print *, b, d end diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 2167de455b8..dc3624f2204 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -10858,6 +10860,8 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, gfc_init_loopinfo (&loop); /* Walk the rhs. */ + if (expr2->value.function.isym) + gfc_strip_kind_from_actual (expr2->value.function.actual); rss = gfc_walk_expr (expr2); if (rss == gfc_ss_terminator) /* The rhs is scalar. Add a ss for the expression. */ diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index d17b623924c..b5ca67198c2 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -5149,8 +5149,8 @@ gfc_conv_intrinsic_dot_product (gfc_se * se, gfc_expr * expr) /* Remove unneeded kind= argument from actual argument list when the result conversion is dealt with in a different place. */ -static void -strip_kind_from_actual (gfc_actual_arglist * actual) +void +gfc_strip_kind_from_actual (gfc_actual_arglist * actual) { for (gfc_actual_arglist *a = actual; a; a = a->next) { @@ -5297,7 +5297,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, enum tree_code op) { gfc_actual_arglist *a; a = actual; - strip_kind_from_actual (a); + gfc_strip_kind_from_actual (a); while (a) { if (a->name && strcmp (a->name, "dim") == 0) diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 16b4215605e..617916fa579 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -821,6 +821,7 @@ void gfc_omp_firstprivatize_type_sizes (struct gimplify_omp_ctx *, tree); /* In trans-intrinsic.c. */ void gfc_conv_intrinsic_mvbits (gfc_se *, gfc_actual_arglist *, gfc_loopinfo *); +void gfc_strip_kind_from_actual (gfc_actual_arglist *); /* Runtime library function decls. */ extern GTY(()) tree gfor_fndecl_pause_numeric;