This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] Fix PR 85102
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: "fortran at gcc dot gnu dot org" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 1 Apr 2018 15:52:15 +0200
- Subject: [patch, fortran] Fix PR 85102
Hello world,
this is a minimal-invasive patch to fix the case where array
specs starting with a parenthesis were not handled correctly.
Regression-tested. OK for trunk?
Regards
Thomas
2018-04-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85102
* array.c (strip_parens): New function.
(match_array_element_spec): Use it to strip away parentheses
from array bounds.
2018-04-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/85102
* gfortran.dg/array_simplify_2.f90: New test.
Index: array.c
===================================================================
--- array.c (revision 258973)
+++ array.c (working copy)
@@ -408,7 +408,23 @@ gfc_resolve_array_spec (gfc_array_spec *as, int ch
return true;
}
+/* Strip away any parentheses around an expression. The argument is
+ assumed to be non-NULL. */
+static void
+strip_parens (gfc_expr *e)
+{
+ gfc_expr *r;
+
+ r = e;
+
+ while (r->expr_type == EXPR_OP && r->value.op.op == INTRINSIC_PARENTHESES)
+ r = r->value.op.op1;
+
+ if (r != e)
+ gfc_replace_expr (e, gfc_copy_expr (r));
+}
+
/* Match a single array element specification. The return values as
well as the upper and lower bounds of the array spec are filled
in according to what we see on the input. The caller makes sure
@@ -457,6 +473,7 @@ match_array_element_spec (gfc_array_spec *as)
if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
return AS_UNKNOWN;
+ strip_parens (*upper);
if (((*upper)->expr_type == EXPR_CONSTANT
&& (*upper)->ts.type != BT_INTEGER) ||
((*upper)->expr_type == EXPR_FUNCTION
@@ -489,6 +506,7 @@ match_array_element_spec (gfc_array_spec *as)
if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
return AS_UNKNOWN;
+ strip_parens (*upper);
if (((*upper)->expr_type == EXPR_CONSTANT
&& (*upper)->ts.type != BT_INTEGER) ||
((*upper)->expr_type == EXPR_FUNCTION
! { dg-do run }
! PR 85102 - this used to ICE
! Original test case by Gerhard Steinmetz
program p
integer, parameter :: a((1+2)) = 1
integer, parameter :: b = dot_product(a, a)
if (b /= 3) stop 1
end