Fortran: Fix fn spec for character-returning functions gcc/fortran/ChangeLog * trans-types.c (create_fn_spec): For character-returning functions, set the hidden string-length argument to 'R' only when the "len=:", i.e. deferred length which goes alongside with allocatable/pointer. diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 220976babb8..637d2c71d01 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -3008,7 +3008,14 @@ create_fn_spec (gfc_symbol *sym, tree fntype) } if (sym->ts.type == BT_CHARACTER) { - spec[spec_len++] = 'R'; + if (!sym->ts.u.cl->length + && ((sym->attr.allocatable && sym->attr.target) + || sym->attr.pointer)) + spec[spec_len++] = '.'; + if (!sym->ts.u.cl->length && sym->attr.allocatable) + spec[spec_len++] = 'w'; + else + spec[spec_len++] = 'R'; spec[spec_len++] = ' '; } }