https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70937
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> --- The following patch fixes the testcase (otherwise untested). Maybe the first fix can be absorbed into this as well. I'll have some time on friday to continue investigating how the fortran FE works but eventually fortran people can lend me a hand here given the following hint. (a little testing shows the assert triggers, needs investigation) Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (revision 235859) +++ gcc/fortran/trans-decl.c (working copy) @@ -6012,6 +6012,22 @@ finish_oacc_declare (gfc_namespace *ns, return; } +static stmtblock_t *place_decl_expr_init; +static void +place_decl_expr (gfc_symbol *sym) +{ + if (sym->backend_decl + && variably_modified_type_p (TREE_TYPE (sym->backend_decl), NULL)) + { + tree type = TREE_TYPE (sym->backend_decl); + while (POINTER_TYPE_P (type)) + type = TREE_TYPE (type); + gcc_assert (TYPE_NAME (type)); + gfc_add_expr_to_block (place_decl_expr_init, + build1 (DECL_EXPR, type, TYPE_NAME (type))); + } +} + /* Generate code for a function. */ @@ -6088,6 +6104,9 @@ gfc_generate_function_code (gfc_namespac has_coarray_vars = false; generate_local_vars (ns); + place_decl_expr_init = &init; + gfc_traverse_ns (ns, place_decl_expr); + if (flag_coarray == GFC_FCOARRAY_LIB && has_coarray_vars) generate_coarray_init (ns);