The following patch fixes PR fortran/78240. It seems to me to be inelegant, but it does pass regression testing. The kludgy portion occurs in decl.c. march_clist_expr is clearly expecting an array with constant dimension due to gcc_assert. When -fdec is used and one takes Gerhard code (see testcase), the assertion is raised. The patch checks for -fdec and failure of spec_size(), and then goes to cleanup. The second part in resolve.c is needed to avoid a NULL pointer dereference when one forgets to use -fdec with Gerhard's code. I did not write a testcase for this, because the dereference occurs in the 5th error message emitted. OK to commit?
2017-11-09 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/78240 * decl.c (match_clist_expr): Reject malformed DEC structure. * resolve.c (match_clist_expr): Avoid NULL pointer deference. 2017-11-09 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/78240 * gfortran.dg/dec_structure_23.f90: new test. Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 254603) +++ gcc/fortran/decl.c (working copy) @@ -735,6 +735,8 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, /* Validate sizes. */ gcc_assert (gfc_array_size (expr, &size)); + if (flag_dec && !spec_size (as, &repeat)) + goto cleanup; gcc_assert (spec_size (as, &repeat)); cmp = mpz_cmp (size, repeat); if (cmp < 0) Index: gcc/fortran/resolve.c =================================================================== --- gcc/fortran/resolve.c (revision 254603) +++ gcc/fortran/resolve.c (working copy) @@ -15284,7 +15290,7 @@ check_data_variable (gfc_data_variable *var, locus *wh if (!gfc_array_size (e, &size)) { gfc_error ("Nonconstant array section at %L in DATA statement", - &e->where); + where); mpz_clear (offset); return false; } Index: gcc/testsuite/gfortran.dg/dec_structure_23.f90 =================================================================== --- gcc/testsuite/gfortran.dg/dec_structure_23.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/dec_structure_23.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! { dg-options "-fdec" } +! PR fortran/78240 +! Contributed by Gerhard Steinmetz +program p + structure /s/ + integer x(n) /1/ ! { dg-error "Unclassifiable statement" } + end structure +end -- Steve