Commit 3e0679c8 by Thomas Koenig

re PR fortran/91550 (ICE in do_subscript, at fortran/frontend-passes.c:2652)

2019-09-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91550
	* frontend-passes.c (do_subscript): If step equals
	zero, a previuos error has been reported; do nothing
	in this case.
	* resolve.c (gfc_resolve_iterator): Move error checking
	after type conversion.

2019-09-15  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/91550
	* gfortran.dg/do_subscript_6.f90: New test.

From-SVN: r275729
parent da903a16
2019-09-15 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/91550
* frontend-passes.c (do_subscript): If step equals
zero, a previuos error has been reported; do nothing
in this case.
* resolve.c (gfc_resolve_iterator): Move error checking
after type conversion.
2019-09-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/91557
......
......@@ -2578,6 +2578,7 @@ do_subscript (gfc_expr **e)
bool have_do_start, have_do_end;
bool error_not_proven;
int warn;
int sgn;
dl = lp->c;
if (dl == NULL)
......@@ -2606,7 +2607,16 @@ do_subscript (gfc_expr **e)
Do not warn in this case. */
if (dl->ext.iterator->step->expr_type == EXPR_CONSTANT)
mpz_init_set (do_step, dl->ext.iterator->step->value.integer);
{
sgn = mpz_cmp_ui (dl->ext.iterator->step->value.integer, 0);
/* This can happen, but then the error has been
reported previously. */
if (sgn == 0)
continue;
mpz_init_set (do_step, dl->ext.iterator->step->value.integer);
}
else
continue;
......@@ -2632,9 +2642,8 @@ do_subscript (gfc_expr **e)
/* No warning inside a zero-trip loop. */
if (have_do_start && have_do_end)
{
int sgn, cmp;
int cmp;
sgn = mpz_cmp_ui (do_step, 0);
cmp = mpz_cmp (do_end, do_start);
if ((sgn > 0 && cmp < 0) || (sgn < 0 && cmp > 0))
break;
......
......@@ -7105,19 +7105,6 @@ gfc_resolve_iterator (gfc_iterator *iter, bool real_ok, bool own_scope)
"Step expression in DO loop"))
return false;
if (iter->step->expr_type == EXPR_CONSTANT)
{
if ((iter->step->ts.type == BT_INTEGER
&& mpz_cmp_ui (iter->step->value.integer, 0) == 0)
|| (iter->step->ts.type == BT_REAL
&& mpfr_sgn (iter->step->value.real) == 0))
{
gfc_error ("Step expression in DO loop at %L cannot be zero",
&iter->step->where);
return false;
}
}
/* Convert start, end, and step to the same type as var. */
if (iter->start->ts.kind != iter->var->ts.kind
|| iter->start->ts.type != iter->var->ts.type)
......@@ -7131,6 +7118,19 @@ gfc_resolve_iterator (gfc_iterator *iter, bool real_ok, bool own_scope)
|| iter->step->ts.type != iter->var->ts.type)
gfc_convert_type (iter->step, &iter->var->ts, 1);
if (iter->step->expr_type == EXPR_CONSTANT)
{
if ((iter->step->ts.type == BT_INTEGER
&& mpz_cmp_ui (iter->step->value.integer, 0) == 0)
|| (iter->step->ts.type == BT_REAL
&& mpfr_sgn (iter->step->value.real) == 0))
{
gfc_error ("Step expression in DO loop at %L cannot be zero",
&iter->step->where);
return false;
}
}
if (iter->start->expr_type == EXPR_CONSTANT
&& iter->end->expr_type == EXPR_CONSTANT
&& iter->step->expr_type == EXPR_CONSTANT)
......
2019-09-15 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/91550
* gfortran.dg/do_subscript_6.f90: New test.
2019-09-15 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/91556
* gfortran.dg/warn_argument_mismatch_1.f90: Remove.
......
! { dg-do compile }
! { dg-options "-std=legacy" }
! PR 91550 - this used to cause an ICE
! Test case by Gerhard Steinmetz
program p
real :: a(3)
integer :: i
do i = 1, 3, .1 ! { dg-error "cannot be zero" }
a(i) = i
end do
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