diff options
author | Fritz Reese <fritzoreese@gmail.com> | 2017-11-14 01:25:26 +0000 |
---|---|---|
committer | Fritz Reese <foreese@gcc.gnu.org> | 2017-11-14 01:25:26 +0000 |
commit | 9b24c104aeb9dcaa06c0fe1324b8d9ef1fc2d92a (patch) | |
tree | 53863fbd54133dd5150bccbeab8db5263c8a0a0c /gcc/fortran/decl.c | |
parent | 728649ebf00526e69d14c334affbf4b162c0f154 (diff) | |
download | gcc-9b24c104aeb9dcaa06c0fe1324b8d9ef1fc2d92a.zip gcc-9b24c104aeb9dcaa06c0fe1324b8d9ef1fc2d92a.tar.gz gcc-9b24c104aeb9dcaa06c0fe1324b8d9ef1fc2d92a.tar.bz2 |
re PR fortran/78240 (ICE in match_clist_expr, at fortran/decl.c:728)
2017-11-13 Fritz Reese <fritzoreese@gmail.com>
PR fortran/78240
gcc/fortran/ChangeLog:
PR fortran/78240
* decl.c (match_clist_expr): Replace gcc_assert with proper
handling of bad result from spec_size().
* resolve.c (check_data_variable): Avoid NULL dereference when passing
locus to gfc_error.
gcc/testsuite/ChangeLog:
PR fortran/78240
* gfortran.dg/dec_structure_23.f90: New.
* gfortran.dg/pr78240.f90: New.
From-SVN: r254718
Diffstat (limited to 'gcc/fortran/decl.c')
-rw-r--r-- | gcc/fortran/decl.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c index 11264e7..e57cfde 100644 --- a/gcc/fortran/decl.c +++ b/gcc/fortran/decl.c @@ -632,14 +632,13 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) gfc_expr *expr = NULL; match m; locus where; - mpz_t repeat, size; + mpz_t repeat, cons_size, as_size; bool scalar; int cmp; gcc_assert (ts); mpz_init_set_ui (repeat, 0); - mpz_init (size); scalar = !as || !as->rank; /* We have already matched '/' - now look for a constant list, as with @@ -733,16 +732,30 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) expr->rank = as->rank; expr->shape = gfc_get_shape (expr->rank); - /* Validate sizes. */ - gcc_assert (gfc_array_size (expr, &size)); - gcc_assert (spec_size (as, &repeat)); - cmp = mpz_cmp (size, repeat); - if (cmp < 0) - gfc_error ("Not enough elements in array initializer at %C"); - else if (cmp > 0) - gfc_error ("Too many elements in array initializer at %C"); + /* Validate sizes. We built expr ourselves, so cons_size will be + constant (we fail above for non-constant expressions). + We still need to verify that the array-spec has constant size. */ + cmp = 0; + gcc_assert (gfc_array_size (expr, &cons_size)); + if (!spec_size (as, &as_size)) + { + gfc_error ("Expected constant array-spec in initializer list at %L", + as->type == AS_EXPLICIT ? &as->upper[0]->where : &where); + cmp = -1; + } + else + { + /* Make sure the specs are of the same size. */ + cmp = mpz_cmp (cons_size, as_size); + if (cmp < 0) + gfc_error ("Not enough elements in array initializer at %C"); + else if (cmp > 0) + gfc_error ("Too many elements in array initializer at %C"); + mpz_clear (as_size); + } + mpz_clear (cons_size); if (cmp) - goto cleanup; + goto cleanup; } /* Make sure scalar types match. */ @@ -754,7 +767,6 @@ match_clist_expr (gfc_expr **result, gfc_typespec *ts, gfc_array_spec *as) expr->ts.u.cl->length_from_typespec = 1; *result = expr; - mpz_clear (size); mpz_clear (repeat); return MATCH_YES; @@ -766,7 +778,6 @@ cleanup: expr->value.constructor = NULL; gfc_free_expr (expr); gfc_constructor_free (array_head); - mpz_clear (size); mpz_clear (repeat); return MATCH_ERROR; } |