aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/arith.c
diff options
context:
space:
mode:
authorThomas Koenig <tkoenig@gcc.gnu.org>2019-12-30 10:34:11 +0000
committerThomas Koenig <tkoenig@gcc.gnu.org>2019-12-30 10:34:11 +0000
commit672511187345d30ccd725214ac4b34b181bd6569 (patch)
tree4dd5ef16a039f4e241f8d2222b19e3661cd794a5 /gcc/fortran/arith.c
parentc3182576ea48f175283e291094298831dd7046e5 (diff)
downloadgcc-672511187345d30ccd725214ac4b34b181bd6569.zip
gcc-672511187345d30ccd725214ac4b34b181bd6569.tar.gz
gcc-672511187345d30ccd725214ac4b34b181bd6569.tar.bz2
Catch division by zero errors in array sizes.
2019-12-30 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/92961 * gfortran.h (gfc_seen_div0): Add declaration. * arith.h (gfc_seen_div0): Add definition. (eval_intrinsic): For integer division by zero, set gfc_seen_div0. * decl.c (variable_decl): If resolution resp. simplification fails for array spec and a division of zero error has been seen, return MATCH_ERROR. 2019-12-30 Thomas Koenig <tkoenig@gcc.gnu.org> PR fortran/92961 * gfortran.dg/arith_divide_2.f90: New test. From-SVN: r279762
Diffstat (limited to 'gcc/fortran/arith.c')
-rw-r--r--gcc/fortran/arith.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/fortran/arith.c b/gcc/fortran/arith.c
index 7f048da..b7699e4 100644
--- a/gcc/fortran/arith.c
+++ b/gcc/fortran/arith.c
@@ -32,6 +32,8 @@ along with GCC; see the file COPYING3. If not see
#include "target-memory.h"
#include "constructor.h"
+bool gfc_seen_div0;
+
/* MPFR does not have a direct replacement for mpz_set_f() from GMP.
It's easily implemented with a few calls though. */
@@ -1620,6 +1622,10 @@ eval_intrinsic (gfc_intrinsic_op op,
gfc_error (gfc_arith_error (rc), &op1->where);
if (rc == ARITH_OVERFLOW)
goto done;
+
+ if (rc == ARITH_DIV0 && op2->ts.type == BT_INTEGER)
+ gfc_seen_div0 = true;
+
return NULL;
}