aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/expr.c
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-12-02 22:33:49 +0100
committerHarald Anlauf <anlauf@gmx.de>2021-12-03 21:07:55 +0100
commitf46d32dd29b7623915e31b0508e2e925526fa7d8 (patch)
treec4b1148f1ca7351c74dd2fa8e00262ad61f6925d /gcc/fortran/expr.c
parentabd7712f91c99690f8b0046ea168b2782afbac69 (diff)
downloadgcc-f46d32dd29b7623915e31b0508e2e925526fa7d8.zip
gcc-f46d32dd29b7623915e31b0508e2e925526fa7d8.tar.gz
gcc-f46d32dd29b7623915e31b0508e2e925526fa7d8.tar.bz2
Fortran: improve checking of array specifications
gcc/fortran/ChangeLog: PR fortran/103505 * array.c (match_array_element_spec): Try to simplify array element specifications to improve early checking. * expr.c (gfc_try_simplify_expr): New. Try simplification of an expression via gfc_simplify_expr. When an error occurs, roll back. * gfortran.h (gfc_try_simplify_expr): Declare it. gcc/testsuite/ChangeLog: PR fortran/103505 * gfortran.dg/pr103505.f90: New test. Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r--gcc/fortran/expr.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 4084d18..8708932 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2331,6 +2331,31 @@ gfc_simplify_expr (gfc_expr *p, int type)
}
+/* Try simplification of an expression via gfc_simplify_expr.
+ When an error occurs (arithmetic or otherwise), roll back. */
+
+bool
+gfc_try_simplify_expr (gfc_expr *e, int type)
+{
+ gfc_expr *n;
+ bool t, saved_div0;
+
+ if (e == NULL || e->expr_type == EXPR_CONSTANT)
+ return true;
+
+ saved_div0 = gfc_seen_div0;
+ gfc_seen_div0 = false;
+ n = gfc_copy_expr (e);
+ t = gfc_simplify_expr (n, type) && !gfc_seen_div0;
+ if (t)
+ gfc_replace_expr (e, n);
+ else
+ gfc_free_expr (n);
+ gfc_seen_div0 = saved_div0;
+ return t;
+}
+
+
/* Returns the type of an expression with the exception that iterator
variables are automatically integers no matter what else they may
be declared as. */