aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2024-02-08 21:51:38 +0100
committerHarald Anlauf <anlauf@gmx.de>2024-02-09 19:24:02 +0100
commitb3d622d70ba209b63471fc1b0970870046e55745 (patch)
tree4eb4d5e0249fbf1f1a94f418c8de988c1192850e /gcc/fortran
parent41a6d2560500a202708e7b661b8b2ad432aee3a6 (diff)
downloadgcc-b3d622d70ba209b63471fc1b0970870046e55745.zip
gcc-b3d622d70ba209b63471fc1b0970870046e55745.tar.gz
gcc-b3d622d70ba209b63471fc1b0970870046e55745.tar.bz2
Fortran: error recovery on arithmetic overflow on unary operations [PR113799]
PR fortran/113799 gcc/fortran/ChangeLog: * arith.cc (reduce_unary): Remember any overflow encountered during reduction of unary arithmetic operations on array constructors and continue, and return error status, but terminate on serious errors. gcc/testsuite/ChangeLog: * gfortran.dg/arithmetic_overflow_2.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r--gcc/fortran/arith.cc11
1 files changed, 8 insertions, 3 deletions
diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index 0598f6a..d17d1aa 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -1323,6 +1323,7 @@ reduce_unary (arith (*eval) (gfc_expr *, gfc_expr **), gfc_expr *op,
gfc_constructor *c;
gfc_expr *r;
arith rc;
+ bool ov = false;
if (op->expr_type == EXPR_CONSTANT)
return eval (op, result);
@@ -1336,13 +1337,17 @@ reduce_unary (arith (*eval) (gfc_expr *, gfc_expr **), gfc_expr *op,
{
rc = reduce_unary (eval, c->expr, &r);
- if (rc != ARITH_OK)
+ /* Remember any overflow encountered during reduction and continue,
+ but terminate on serious errors. */
+ if (rc == ARITH_OVERFLOW)
+ ov = true;
+ else if (rc != ARITH_OK)
break;
gfc_replace_expr (c->expr, r);
}
- if (rc != ARITH_OK)
+ if (rc != ARITH_OK && rc != ARITH_OVERFLOW)
gfc_constructor_free (head);
else
{
@@ -1363,7 +1368,7 @@ reduce_unary (arith (*eval) (gfc_expr *, gfc_expr **), gfc_expr *op,
*result = r;
}
- return rc;
+ return ov ? ARITH_OVERFLOW : rc;
}