From: Thomas Koenig Date: Sun, 15 Sep 2019 14:57:48 +0000 (+0000) Subject: re PR fortran/91550 (ICE in do_subscript, at fortran/frontend-passes.c:2652) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=3e0679c8d4e22f00614a52cbd2b33780f3f1a911;p=gcc.git re PR fortran/91550 (ICE in do_subscript, at fortran/frontend-passes.c:2652) 2019-09-15 Thomas Koenig 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 PR fortran/91550 * gfortran.dg/do_subscript_6.f90: New test. From-SVN: r275729 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 56a107dae0a..1006cbda2f4 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2019-09-15 Thomas Koenig + + 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 PR fortran/91557 diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c index b095d5f3420..87518b8b7d8 100644 --- a/gcc/fortran/frontend-passes.c +++ b/gcc/fortran/frontend-passes.c @@ -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; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index c4260bbb09c..ce192bbb189 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1ec4fb9c9ef..c06029ac75c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-09-15 Thomas Koenig + + PR fortran/91550 + * gfortran.dg/do_subscript_6.f90: New test. + 2019-09-15 Thomas Koenig PR fortran/91556 diff --git a/gcc/testsuite/gfortran.dg/do_subscript_6.f90 b/gcc/testsuite/gfortran.dg/do_subscript_6.f90 new file mode 100644 index 00000000000..d78b9d39056 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/do_subscript_6.f90 @@ -0,0 +1,11 @@ +! { 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