diff mbox series

[fortran] Fix PR 85102

Message ID 93e78b0a-8086-d67b-4c6e-08de258f7af7@netcologne.de
State New
Headers show
Series [fortran] Fix PR 85102 | expand

Commit Message

Thomas Koenig April 1, 2018, 1:52 p.m. UTC
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.

Comments

Thomas Koenig April 1, 2018, 10:09 p.m. UTC | #1
Hi everybody,

> Regression-tested. OK for trunk?

Not OK, since it misses

    integer, parameter :: a((1+1)+1) = 1

as asked by Dominique on IRC.  Good catch!

I'll look at this tomorrow.

Regards

	thomas
diff mbox series

Patch

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