From: Harald Anlauf Date: Wed, 25 Nov 2020 19:20:44 +0000 (+0100) Subject: PR fortran/85796 - Floating point exception with implied do X-Git-Tag: releases/gcc-10.3.0~580 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67e7f56b6795023dbf59d27e200668b04ce63c3a;p=thirdparty%2Fgcc.git PR fortran/85796 - Floating point exception with implied do Catch invalid step=0 in implied do loop within data statements. gcc/fortran/ChangeLog: PR fortran/85796 * resolve.c (traverse_data_list): Fix copy&paste errors; catch step=0 in implied do loop. gcc/testsuite/ChangeLog: PR fortran/85796 * gfortran.dg/pr85796.f90: New test. (cherry picked from commit 94172dc7091a2c6b2d2f99857de77c607fac3935) --- diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 0d9908e912f3..0eb650bce616 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -16271,7 +16271,7 @@ traverse_data_list (gfc_data_variable *var, locus *where) || end->expr_type != EXPR_CONSTANT) { gfc_error ("end of implied-do loop at %L could not be " - "simplified to a constant value", &start->where); + "simplified to a constant value", &end->where); retval = false; goto cleanup; } @@ -16279,7 +16279,14 @@ traverse_data_list (gfc_data_variable *var, locus *where) || step->expr_type != EXPR_CONSTANT) { gfc_error ("step of implied-do loop at %L could not be " - "simplified to a constant value", &start->where); + "simplified to a constant value", &step->where); + retval = false; + goto cleanup; + } + if (mpz_cmp_si (step->value.integer, 0) == 0) + { + gfc_error ("step of implied-do loop at %L shall not be zero", + &step->where); retval = false; goto cleanup; } diff --git a/gcc/testsuite/gfortran.dg/pr85796.f90 b/gcc/testsuite/gfortran.dg/pr85796.f90 new file mode 100644 index 000000000000..78683787fbb3 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr85796.f90 @@ -0,0 +1,8 @@ +! { dg-do compile } +! PR fortran/85796 - Floating point exception with implied do in data statement + +program p + implicit none + integer :: i, j, x(2,2) + data ((x(i,j),i=1,2,j-1),j=1,2) /3*789/ ! { dg-error "step of implied-do loop" } +end