public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 85102, take 2
@ 2018-04-02 12:05 Thomas König
  2018-04-02 14:03 ` Steve Kargl
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas König @ 2018-04-02 12:05 UTC (permalink / raw)
  To: fortran, gcc-patches, Dominique Dhumieres

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

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.

[-- Attachment #2: array_simplify_2.f90 --]
[-- Type: text/x-fortran, Size: 329 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((1+1)+1) = 1
   integer, parameter :: c = dot_product(a, a)
   integer, parameter :: d = dot_product(b,b)
   if (c /= 3) stop 1
   if (d /= 3) stop 2
 end program p

[-- Attachment #3: p3.diff --]
[-- Type: text/x-patch, Size: 792 bytes --]

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;

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

* Re: [patch, fortran] Fix PR 85102, take 2
  2018-04-02 12:05 [patch, fortran] Fix PR 85102, take 2 Thomas König
@ 2018-04-02 14:03 ` Steve Kargl
  2018-04-02 16:23   ` Thomas König
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Kargl @ 2018-04-02 14:03 UTC (permalink / raw)
  To: Thomas König; +Cc: fortran, gcc-patches, Dominique Dhumieres

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?

-- 
Steve

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

* Re: [patch, fortran] Fix PR 85102, take 2
  2018-04-02 14:03 ` Steve Kargl
@ 2018-04-02 16:23   ` Thomas König
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas König @ 2018-04-02 16:23 UTC (permalink / raw)
  To: sgk; +Cc: fortran, gcc-patches, Dominique Dhumieres

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

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

end of thread, other threads:[~2018-04-02 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-02 12:05 [patch, fortran] Fix PR 85102, take 2 Thomas König
2018-04-02 14:03 ` Steve Kargl
2018-04-02 16:23   ` Thomas König

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).