Hello world, the attached patch fixes an ICE on valid for INDEX (see test case). The problem was that the KIND argument was still present during scalarization, which caused the ICE. The fix is to remove the KIND argument, and the best place to do this is in resolution. I did try to do this in gfc_conv_intrinsic_index_scan_verify, but it is too late by then. Removing the KIND argument required changing the call signature of gfc_resolve_index_func, which in turn required the rest of the changes (including the one in trans-decl.c - I am not convinced that what we are doing there is right, but for this bug fix, I left the functionality as is). Regression-tested. OK for trunk? Regards Thomas 2019-12-19 Thomas Koenig PR fortran/91541 * intrinsic.c (add_sym_4ind): New function. (add_functions): Use it for INDEX. (resolve_intrinsic): Also call f1m for INDEX. * intrinsic.h (gfc_resolve_index_func): Adjust prototype to take a gfc_arglist instead of individual arguments. * iresolve.c (gfc_resolve_index_func): Adjust arguments. Remove KIND argument if present, and make sure this is not done twice. * trans-decl.c: Include "intrinsic.h". (gfc_get_extern_function_decl): Special case for resolving INDEX. 2019-12-19 Thomas Koenig PR fortran/91541 * gfortran.dg/index_3.f90: New test.