Patchwork [Fortran] PR 44742 - Avoid ICE when -fmax-array-constructor is exeeded

login
register
mail settings
Submitter Tobias Burnus
Date July 6, 2010, 4:10 p.m.
Message ID <4C335569.1030201@net-b.de>
Download mbox | patch
Permalink /patch/58045/
State New
Headers show

Comments

Tobias Burnus - July 6, 2010, 4:10 p.m.
The patch adds a diagnostic for "constant" (F95, F2008; F2003:
"initialization") expressions where the array constructor exceeds the
limit given by  -fmax-array-constructor -- thus fixing an ICE.

The error message has been copied from array.c's gfc_expand_constructor.
Thus, if you don't like it, one should change it there and in
trans-array.c's gfc_conv_array_initializer as well. (Actually, I do not
like the wording much, but did not immediately come up with something else.)

Build and currently regtesting on x86-64-linux.
OK for the trunk when it succeeded?

 * * *

The patch (as posted in the PR) was approved by Jerry on IRC - I thus
intent to commit it after regtesting finished.

Tobias
Jerry DeLisle - July 6, 2010, 8:33 p.m.
On 07/06/2010 09:10 AM, Tobias Burnus wrote:
> The patch adds a diagnostic for "constant" (F95, F2008; F2003:
> "initialization") expressions where the array constructor exceeds the
> limit given by  -fmax-array-constructor -- thus fixing an ICE.
>
> The error message has been copied from array.c's gfc_expand_constructor.
> Thus, if you don't like it, one should change it there and in
> trans-array.c's gfc_conv_array_initializer as well. (Actually, I do not
> like the wording much, but did not immediately come up with something else.)
>
> Build and currently regtesting on x86-64-linux.
> OK for the trunk when it succeeded?
>
>   * * *
>
> The patch (as posted in the PR) was approved by Jerry on IRC - I thus
> intent to commit it after regtesting finished.

Yes, OK and thanks for patch.

Jerry

Patch

2010-07-06  Tobias Burnus  <burnus@net-b.de>

	PR fortran/44742
	* array.c (gfc_expand_constructor): Add optional diagnostic.
	* gfortran.h (gfc_expand_constructor): Update prototype.
	* expr.c (gfc_simplify_expr, check_init_expr,
	gfc_reduce_init_expr): Update gfc_expand_constructor call.
	* resolve.c (gfc_resolve_expr): Ditto.

2010-07-06  Tobias Burnus  <burnus@net-b.de>

	PR fortran/44742
	* gfortran.dg/parameter_array_init_6.f90: New.

diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c
index 64816f2..0c36f54 100644
--- a/gcc/fortran/array.c
+++ b/gcc/fortran/array.c
@@ -1545,7 +1545,7 @@  gfc_get_array_element (gfc_expr *array, int element)
    constructor if they are small enough.  */
 
 gfc_try
-gfc_expand_constructor (gfc_expr *e)
+gfc_expand_constructor (gfc_expr *e, bool fatal)
 {
   expand_info expand_save;
   gfc_expr *f;
@@ -1557,6 +1557,15 @@  gfc_expand_constructor (gfc_expr *e)
   if (f != NULL)
     {
       gfc_free_expr (f);
+      if (fatal)
+	{
+	  gfc_error ("The number of elements in the array constructor "
+		     "at %L requires an increase of the allowed %d "
+		     "upper limit.   See -fmax-array-constructor "
+		     "option", &e->where,
+		     gfc_option.flag_max_array_constructor);
+	  return FAILURE;
+	}
       return SUCCESS;
     }
 
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index c876fdd..12a46a9 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1894,7 +1894,7 @@  gfc_simplify_expr (gfc_expr *p, int type)
 
       if (p->expr_type == EXPR_ARRAY && p->ref && p->ref->type == REF_ARRAY
 	  && p->ref->u.ar.type == AR_FULL)
-	  gfc_expand_constructor (p);
+	  gfc_expand_constructor (p, false);
 
       if (simplify_const_ref (p) == FAILURE)
 	return FAILURE;
@@ -2573,7 +2573,7 @@  check_init_expr (gfc_expr *e)
       if (t == FAILURE)
 	break;
 
-      t = gfc_expand_constructor (e);
+      t = gfc_expand_constructor (e, true);
       if (t == FAILURE)
 	break;
 
@@ -2609,7 +2609,7 @@  gfc_reduce_init_expr (gfc_expr *expr)
     {
       if (gfc_check_constructor_type (expr) == FAILURE)
 	return FAILURE;
-      if (gfc_expand_constructor (expr) == FAILURE)
+      if (gfc_expand_constructor (expr, true) == FAILURE)
 	return FAILURE;
     }
 
diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index 0c96bf4..a63f97e 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -2715,7 +2715,7 @@  gfc_try gfc_resolve_array_spec (gfc_array_spec *, int);
 int gfc_compare_array_spec (gfc_array_spec *, gfc_array_spec *);
 
 void gfc_simplify_iterator_var (gfc_expr *);
-gfc_try gfc_expand_constructor (gfc_expr *);
+gfc_try gfc_expand_constructor (gfc_expr *, bool);
 int gfc_constant_ac (gfc_expr *);
 int gfc_expanded_ac (gfc_expr *);
 gfc_try gfc_resolve_character_array_constructor (gfc_expr *);
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 4e11fc6..a8ed544 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -5776,7 +5776,7 @@  gfc_resolve_expr (gfc_expr *e)
 	{
 	  expression_rank (e);
 	  if (gfc_is_constant_expr (e) || gfc_is_expandable_expr (e))
-	    gfc_expand_constructor (e);
+	    gfc_expand_constructor (e, false);
 	}
 
       /* This provides the opportunity for the length of constructors with
@@ -5786,7 +5786,7 @@  gfc_resolve_expr (gfc_expr *e)
         {
 	  /* For efficiency, we call gfc_expand_constructor for BT_CHARACTER
 	     here rather then add a duplicate test for it above.  */ 
-	  gfc_expand_constructor (e);
+	  gfc_expand_constructor (e, false);
 	  t = gfc_resolve_character_array_constructor (e);
 	}
 
--- /dev/null	2010-07-05 20:28:01.219304931 +0200
+++ b/gcc/testsuite/gfortran.dg/parameter_array_init_6.f90	2010-07-06 17:26:34.000000000 +0200
@@ -0,0 +1,18 @@ 
+! { dg-do compile }
+!
+! PR fortran/44742
+!
+! Test case based on Juergen Reuter's and reduced by
+! Janus Weil.
+!
+! The program creates a large array constructor, which
+! exceeds -fmax-array-constructor - and caused an ICE.
+!
+
+module proc8
+  implicit none
+  integer, parameter :: N = 256
+  logical, dimension(N**2), parameter :: A = .false.
+  logical, dimension(N,N), parameter :: B &
+    = reshape ( (/ A /), (/ N, N /) ) ! { dg-error "array constructor at .1. requires an increase" }
+end module