https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92305
--- Comment #18 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I believe this is a FE bug, for these functions TYPE_ARG_TYPES of the FUNCTION_TYPE show just 6 arguments and don't include those 4 extra boolean args for the scalar optional dummy vars, and as the function isn't varargs either, it just confuses the calls.c completely, because it has more arguments than really allowed. --- gcc/fortran/trans-types.c.jj 2020-01-12 11:54:36.000000000 +0100 +++ gcc/fortran/trans-types.c 2020-01-31 21:26:34.199188677 +0100 @@ -3098,6 +3098,16 @@ gfc_get_function_type (gfc_symbol * sym, vec_safe_push (typelist, type); } + /* For noncharacter scalar intrinsic types, VALUE passes the value, + hence, the optional status cannot be transferred via a NULL pointer. + Thus, we will use a hidden argument in that case. */ + else if (arg + && arg->attr.optional + && arg->attr.value + && !arg->attr.dimension + && arg->ts.type != BT_CLASS + && !gfc_bt_struct (arg->ts.type)) + vec_safe_push (typelist, boolean_type_node); } if (!vec_safe_is_empty (typelist) --- gcc/fortran/trans-decl.c.jj 2020-01-30 09:34:43.207088430 +0100 +++ gcc/fortran/trans-decl.c 2020-01-31 21:28:49.272197084 +0100 @@ -2645,8 +2645,8 @@ create_function_arglist (gfc_symbol * sy || f->sym->ts.u.cl->backend_decl == length) { if (POINTER_TYPE_P (len_type)) - f->sym->ts.u.cl->backend_decl = - build_fold_indirect_ref_loc (input_location, length); + f->sym->ts.u.cl->backend_decl + = build_fold_indirect_ref_loc (input_location, length); else if (f->sym->ts.u.cl->backend_decl == NULL) gfc_create_string_length (f->sym); @@ -2677,6 +2677,8 @@ create_function_arglist (gfc_symbol * sy DECL_ARG_TYPE (tmp) = boolean_type_node; TREE_READONLY (tmp) = 1; gfc_finish_decl (tmp); + + hidden_typelist = TREE_CHAIN (hidden_typelist); } /* For non-constant length array arguments, make sure they use seems to fix this, will see how far I get with that.