The following makes sure to create DECL_EXPRs for VLA types built for temporary arrays to properly allow the gimplifier to unshare expression in its type fields when required.
This avoids turing those fields into garbage. With a patch to allow the gimplifier to introduce SSA names it avoids ICEs for gfortran.dg/auto_char_pointer_array_result_1.f90 gfortran.dg/interface_12.f90 gfortran.dg/result_in_spec_1.f90 and libgomp.fortran/vla7.f90 Bootstrapped and tested on x86_64-unknown-linux-gnu. Ok for trunk? I'm not sure testsuite coverage catched all cases this was missing so other places might need similar handling after the SSA patch goes in and this gets applied to the real world (TM). Thanks, Richard. 2016-04-29 Richard Biener <rguent...@suse.de> fortran/ * trans-array.c (gfc_trans_create_temp_array): Properly create a DECL_EXPR for the anonymous VLA array type. Index: gcc/fortran/trans-array.c =================================================================== *** gcc/fortran/trans-array.c.orig 2016-04-28 14:11:00.064581449 +0200 --- gcc/fortran/trans-array.c 2016-04-28 14:11:08.120671151 +0200 *************** gfc_trans_create_temp_array (stmtblock_t *** 1094,1099 **** --- 1094,1109 ---- info->descriptor = desc; size = gfc_index_one_node; + /* Emit a DECL_EXPR for the variable sized array type in + GFC_TYPE_ARRAY_DATAPTR_TYPE so the gimplification of its type + sizes works correctly. */ + tree arraytype = TREE_TYPE (GFC_TYPE_ARRAY_DATAPTR_TYPE (type)); + if (! TYPE_NAME (arraytype)) + TYPE_NAME (arraytype) = build_decl (UNKNOWN_LOCATION, TYPE_DECL, + NULL_TREE, arraytype); + gfc_add_expr_to_block (pre, build1 (DECL_EXPR, + arraytype, TYPE_NAME (arraytype))); + /* Fill in the array dtype. */ tmp = gfc_conv_descriptor_dtype (desc); gfc_add_modify (pre, tmp, gfc_get_dtype (TREE_TYPE (desc)));