public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/43996 -- Too large array constructor in SPREAD
@ 2015-11-17 16:05 Steve Kargl
  2015-11-18  6:23 ` Jerry DeLisle
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2015-11-17 16:05 UTC (permalink / raw)
  To: fortran, gcc-patches

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

The attached patch fixes an issue with SPREAD and the PARAMETER
attribute when an array constructor is too large for expansion.
gfortran now issues an error message and points to the 
-fmax-array-constructor.

Patch built on i386-*-freebsd and x86_64-*-freebsd.  There are
no regressions.  OK to commit?

2015-11-17  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/43996
	* simplify.c (gfc_simplify_spread): Issue error for too large array 
	constructor in a PARAMETER statement.

2015-11-17  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/43996
	* gfortran.dg/pr43996.f90

-- 
Steve

[-- Attachment #2: pr43996.diff --]
[-- Type: text/x-diff, Size: 1664 bytes --]

Index: gcc/fortran/simplify.c
===================================================================
--- gcc/fortran/simplify.c	(revision 230463)
+++ gcc/fortran/simplify.c	(working copy)
@@ -5991,8 +5991,8 @@ gfc_simplify_spacing (gfc_expr *x)
 gfc_expr *
 gfc_simplify_spread (gfc_expr *source, gfc_expr *dim_expr, gfc_expr *ncopies_expr)
 {
-  gfc_expr *result = 0L;
-  int i, j, dim, ncopies;
+  gfc_expr *result = NULL;
+  int nelem, i, j, dim, ncopies;
   mpz_t size;
 
   if ((!gfc_is_constant_expr (source)
@@ -6019,8 +6019,20 @@ gfc_simplify_spread (gfc_expr *source, g
   else
     mpz_init_set_ui (size, 1);
 
-  if (mpz_get_si (size)*ncopies > flag_max_array_constructor)
-    return NULL;
+  nelem = mpz_get_si (size) * ncopies;
+  if (nelem > flag_max_array_constructor)
+    {
+      if (gfc_current_ns->sym_root->n.sym->attr.flavor == FL_PARAMETER)
+	{
+	  gfc_error ("The number of elements (%d) in the array constructor "
+		     "at %L requires an increase of the allowed %d upper "
+		     "limit.  See %<-fmax-array-constructor%> option.",
+		     nelem, &source->where, flag_max_array_constructor);
+	  return &gfc_bad_expr;
+	}
+      else
+	return NULL;
+    }
 
   if (source->expr_type == EXPR_CONSTANT)
     {
Index: gcc/testsuite/gfortran.dg/pr43996.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr43996.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr43996.f90	(working copy)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! PR fortran/43996
+!
+real, parameter :: a(720,360) = spread((/(j, j=1,720) /), dim=2, ncopies=360) ! { dg-error "number of elements" }
+real x
+x = a(720,360)
+end

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

* Re: [PATCH] PR fortran/43996 -- Too large array constructor in SPREAD
  2015-11-17 16:05 [PATCH] PR fortran/43996 -- Too large array constructor in SPREAD Steve Kargl
@ 2015-11-18  6:23 ` Jerry DeLisle
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry DeLisle @ 2015-11-18  6:23 UTC (permalink / raw)
  To: Steve Kargl, fortran, gcc-patches

On 11/17/2015 08:05 AM, Steve Kargl wrote:
> The attached patch fixes an issue with SPREAD and the PARAMETER
> attribute when an array constructor is too large for expansion.
> gfortran now issues an error message and points to the 
> -fmax-array-constructor.
> 
> Patch built on i386-*-freebsd and x86_64-*-freebsd.  There are
> no regressions.  OK to commit?
> 
OK

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

end of thread, other threads:[~2015-11-18  6:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-17 16:05 [PATCH] PR fortran/43996 -- Too large array constructor in SPREAD Steve Kargl
2015-11-18  6:23 ` Jerry DeLisle

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