The KIND argument of the INDEX intrinsic is a compile time constant that is used at compile time only to resolve to a kind-specific library method. It is otherwise completely ignored at runtime, and there is no code generated for it as the library procedure has no kind argument. This confuses the scalarizer which expects to see every argument of elemental functions to be used when calling a procedure. This change removes the argument from the scalarization lists at the beginning of the scalarization process, so that the argument is completely ignored. gcc/fortran/ PR fortran/97896 * gfortran.h (gfc_dummy_arg::get_name): New method. (gfc_formal_arglist::get_name, gfc_intrinsic_arg::get_name): Declare new methods. * symbol.c (gfc_formal_arglist::get_name): Implement new method. * intrinsic.c (gfc_intrinsic_arg::get_name): Same. * trans-array.h (gfc_get_intrinsic_for_expr, gfc_get_proc_ifc_for_expr): New. * trans-array.c (gfc_get_intrinsic_for_expr, arg_evaluated_for_scalarization): New. (gfc_walk_elemental_function_args): Add intrinsic procedure as argument. Check arg_evaluated_for_scalarization. * trans-intrinsic.c (gfc_walk_intrinsic_function): Update call. * trans-stmt.c (get_intrinsic_for_code): New. (gfc_trans_call): Update call. gcc/testsuite/ PR fortran/97896 * gfortran.dg/index_5.f90: New. --- gcc/fortran/gfortran.h | 3 ++ gcc/fortran/intrinsic.c | 6 +++ gcc/fortran/symbol.c | 6 +++ gcc/fortran/trans-array.c | 53 ++++++++++++++++++++++++++- gcc/fortran/trans-array.h | 3 ++ gcc/fortran/trans-intrinsic.c | 1 + gcc/fortran/trans-stmt.c | 20 ++++++++++ gcc/testsuite/gfortran.dg/index_5.f90 | 23 ++++++++++++ 8 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/index_5.f90