public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 85102
@ 2018-04-01 13:52 Thomas Koenig
  2018-04-01 22:09 ` Thomas Koenig
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2018-04-01 13:52 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 545 bytes --]

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.

[-- Attachment #2: p2.diff --]
[-- Type: text/x-patch, Size: 1410 bytes --]

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

[-- Attachment #3: array_simplify_2.f90 --]
[-- Type: text/x-fortran, Size: 210 bytes --]

! { 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch, fortran] Fix PR 85102
  2018-04-01 13:52 [patch, fortran] Fix PR 85102 Thomas Koenig
@ 2018-04-01 22:09 ` Thomas Koenig
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2018-04-01 22:09 UTC (permalink / raw)
  To: fortran, gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-04-01 22:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-01 13:52 [patch, fortran] Fix PR 85102 Thomas Koenig
2018-04-01 22:09 ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).