public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [PATCH] PR fortran/43996 -- Too large array constructor in SPREAD
Date: Tue, 17 Nov 2015 16:05:00 -0000	[thread overview]
Message-ID: <20151117160516.GA41964@troutmask.apl.washington.edu> (raw)

[-- 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

             reply	other threads:[~2015-11-17 16:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-17 16:05 Steve Kargl [this message]
2015-11-18  6:23 ` Jerry DeLisle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151117160516.GA41964@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).