------- Comment #2 from taschna at uni-muenster dot de 2006-07-27 22:38 ------- I'm an absolute beginner in programming gfortran, but the following patch seems to solve this bug by inserting an if-block into the code in order to prevent the access to the NULL pointer in case the array is pointing to NULL.
Index: gcc/fortran/trans-array.c =================================================================== --- gcc/fortran/trans-array.c (revision 115751) +++ gcc/fortran/trans-array.c (working copy) @@ -3656,7 +3656,9 @@ gfc_trans_g77_array (gfc_symbol * sym, t locus loc; tree offset; tree tmp; + tree stmt; stmtblock_t block; + bool optional_arg; gfc_get_backend_locus (&loc); gfc_set_backend_locus (&sym->declared_at); @@ -3685,13 +3687,22 @@ gfc_trans_g77_array (gfc_symbol * sym, t tmp = convert (TREE_TYPE (parm), GFC_DECL_SAVED_DESCRIPTOR (parm)); gfc_add_modify_expr (&block, parm, tmp); } - tmp = gfc_finish_block (&block); + stmt = gfc_finish_block (&block); gfc_set_backend_locus (&loc); gfc_start_block (&block); /* Add the initialization code to the start of the function. */ - gfc_add_expr_to_block (&block, tmp); + optional_arg = (sym->attr.optional + || (sym->ns->proc_name->attr.entry_master + && sym->attr.dummy)); + if (optional_arg) + { + tmp = gfc_conv_expr_present (sym); + stmt = build3_v (COND_EXPR, tmp, stmt, build_empty_stmt ()); + } + + gfc_add_expr_to_block (&block, stmt); gfc_add_expr_to_block (&block, body); return gfc_finish_block (&block); -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25818