+2017-11-13 Fritz Reese <fritzoreese@gmail.com>
+
+ 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.
+
2017-11-11 Janus Weil <janus@gcc.gnu.org>
PR fortran/82932
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
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. */
expr->ts.u.cl->length_from_typespec = 1;
*result = expr;
- mpz_clear (size);
mpz_clear (repeat);
return MATCH_YES;
expr->value.constructor = NULL;
gfc_free_expr (expr);
gfc_constructor_free (array_head);
- mpz_clear (size);
mpz_clear (repeat);
return MATCH_ERROR;
}
--- /dev/null
+! { dg-do compile }
+! { dg-options "-fdec-structure" }
+!
+! PR fortran/78240
+!
+! Test a regression where an ICE occurred attempting to create array variables
+! with non-constant array-specs in legacy clist initializers.
+!
+
+program p
+ implicit none
+ integer :: nn
+ real :: rr
+ structure /s/
+ integer x(n) /1/ ! { dg-error "xpected constant" }
+ integer xx(nn) /1/ ! { dg-error "xpected constant" }
+ integer xxx(rr) /1.0/ ! { dg-error "xpected constant" }
+ end structure
+end