diff mbox series

[fortran] Fix PR 85102, take 2

Message ID db8f2678-f42b-cf1d-4663-a13a35382e39@tkoenig.net
State New
Headers show
Series [fortran] Fix PR 85102, take 2 | expand

Commit Message

Thomas König April 2, 2018, 12:05 p.m. UTC
Hello world,

here is the second version of the fix for PR 85102. This
is a much more general approach, which actually uses simplification
(while avoiding some "interesting" regressions when resolving, or
simplifying, too soon...)

Thanks to Dominique for the hint about the problem with my first patch.

Regression-tested. OK for trunk?

Regards

	Thomas

2018-04-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/85102
         * decl.c (variable_decl): If upper or lower bounds simplify
         to a constant, use that.

2018-04-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/85102
         * gfortran.dg/array_simplify_2.f90: New test.

Comments

Steve Kargl April 2, 2018, 2:03 p.m. UTC | #1
On Mon, Apr 02, 2018 at 02:05:29PM +0200, Thomas König wrote:
> +      if (as->type == AS_EXPLICIT)
> +	{
> +	  for (int i = 0; i < as->rank; i++)
> +	    {
> +	      gfc_expr *e, *n;
> +	      e = as->lower[i];
> +	      if (e->expr_type != EXPR_CONSTANT)
> +		{
> +		  n = gfc_copy_expr (e);
> +		  gfc_simplify_expr (n, 1);
> +		  if (n->expr_type == EXPR_CONSTANT)
> +		    gfc_replace_expr (e, n);
                  else
                    gfc_free_expr (n);
> +		}
> +	      e = as->upper[i];
> +	      if (e->expr_type != EXPR_CONSTANT)
> +		{
> +		  n = gfc_copy_expr (e);
> +		  gfc_simplify_expr (n, 1);
> +		  if (n->expr_type == EXPR_CONSTANT)
> +		    gfc_replace_expr (e, n);
                  else
                    gfc_free_expr (n);

> +		}
> +	    }
> +	}

Don't you need the above changes to avoid leaking memory?
Thomas König April 2, 2018, 4:23 p.m. UTC | #2
Hi Steve,

>                    else
>                      gfc_free_expr (n);
> 
> Don't you need the above changes to avoid leaking memory?

Correct.

OK with those changes?

Regards

	Thomas
diff mbox series

Patch

Index: decl.c
===================================================================
--- decl.c	(revision 258845)
+++ decl.c	(working copy)
@@ -2424,6 +2424,29 @@  variable_decl (int elem)
 	      goto cleanup;
 	    }
 	}
+      if (as->type == AS_EXPLICIT)
+	{
+	  for (int i = 0; i < as->rank; i++)
+	    {
+	      gfc_expr *e, *n;
+	      e = as->lower[i];
+	      if (e->expr_type != EXPR_CONSTANT)
+		{
+		  n = gfc_copy_expr (e);
+		  gfc_simplify_expr (n, 1);
+		  if (n->expr_type == EXPR_CONSTANT)
+		    gfc_replace_expr (e, n);
+		}
+	      e = as->upper[i];
+	      if (e->expr_type != EXPR_CONSTANT)
+		{
+		  n = gfc_copy_expr (e);
+		  gfc_simplify_expr (n, 1);
+		  if (n->expr_type == EXPR_CONSTANT)
+		    gfc_replace_expr (e, n);
+		}
+	    }
+	}
     }
 
   char_len = NULL;