+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
bool have_do_start, have_do_end;
bool error_not_proven;
int warn;
+ int sgn;
dl = lp->c;
if (dl == NULL)
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;
/* 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;
"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)
|| 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
--- /dev/null
+! { 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