http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57306
--- Comment #4 from janus at gcc dot gnu.org --- Here is an enhanced patch which regtests cleanly: Index: gcc/fortran/trans-decl.c =================================================================== --- gcc/fortran/trans-decl.c (revision 201253) +++ gcc/fortran/trans-decl.c (working copy) @@ -1491,14 +1491,16 @@ gfc_get_symbol_decl (gfc_symbol * sym) SAVE is specified otherwise they need to be reinitialized every time the procedure is entered. The TREE_STATIC is in this case due to -fmax-stack-var-size=. */ + bool ptr = sym->attr.pointer || sym->attr.allocatable + || (sym->ts.type == BT_CLASS + && CLASS_DATA (sym)->attr.class_pointer); + DECL_INITIAL (decl) = gfc_conv_initializer (sym->value, &sym->ts, TREE_TYPE (decl), sym->attr.dimension || (sym->attr.codimension && sym->attr.allocatable), - sym->attr.pointer - || sym->attr.allocatable, - sym->attr.proc_pointer); + ptr, sym->attr.proc_pointer); } if (!TREE_STATIC (decl) Index: gcc/fortran/trans-expr.c =================================================================== --- gcc/fortran/trans-expr.c (revision 201253) +++ gcc/fortran/trans-expr.c (working copy) @@ -5664,7 +5664,18 @@ gfc_conv_initializer (gfc_expr * expr, gfc_typespe else if (pointer || procptr) { if (!expr || expr->expr_type == EXPR_NULL) - return fold_convert (type, null_pointer_node); + { + if (ts->type == BT_CLASS) + { + gfc_init_se (&se, NULL); + gfc_conv_structure (&se, gfc_class_null_initializer(ts, expr), 1); + gcc_assert (TREE_CODE (se.expr) == CONSTRUCTOR); + TREE_STATIC (se.expr) = 1; + return se.expr; + } + else + return fold_convert (type, null_pointer_node); + } else { gfc_init_se (&se, NULL);