Commit 9b24c104 by Fritz Reese Committed by Fritz Reese

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
parent 728649eb
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
......
......@@ -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;
}
......
......@@ -15286,7 +15286,7 @@ check_data_variable (gfc_data_variable *var, locus *where)
if (!gfc_array_size (e, &size))
{
gfc_error ("Nonconstant array section at %L in DATA statement",
&e->where);
where);
mpz_clear (offset);
return false;
}
......
2017-11-13 Fritz Reese <fritzoreese@gmail.com>
PR fortran/78240
* gfortran.dg/dec_structure_23.f90: New.
* gfortran.dg/pr78240.f90: New.
2017-11-13 Carl Love <cel@us.ibm.com>
* gcc.target/powerpc/builtin-vec-sums-be-int.c: New test file.
......
! { 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
! { dg-do compile }
!
! PR fortran/78240
!
! Test a regression where an ICE occurred by passing an invalid reference
! to the error handling routine for non-constant array-specs in DATA list
! initializers.
!
program p
integer x(n) /1/ ! { dg-error "Nonconstant array" }
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment