This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR29060 - spread causes ICE in gfc_trans_array_constructor
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: patch <gcc-patches at gcc dot gnu dot org>, "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Sun, 17 Sep 2006 13:39:21 +0200
- Subject: [Patch, fortran] PR29060 - spread causes ICE in gfc_trans_array_constructor
:ADDPATCH fortran:
This ICE is caused by an assignment in which no shape information was
being provided to the scalarizer. This patch makes the information
available using the shape of the source, the dim and the ncopies
parameters, as long as they are all available and constant. The
testcase is that provided by the reporter with the addition of the case
where the sourec and the inserted dimension are the other way round
(yes, I got it wrong the first time...).
Regtested on FC5/Athlon - OK for trunk and 4.1?
Paul
2006-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29060
* iresolve.c (resolve_spread): Build shape for result if the
source shape is available and dim and ncopies are constants.
2006-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29060
* gfortran.dg/spread_shape_1.f90: New test.
Index: gcc/fortran/iresolve.c
===================================================================
*** gcc/fortran/iresolve.c (revision 116947)
--- gcc/fortran/iresolve.c (working copy)
*************** gfc_resolve_spread (gfc_expr * f, gfc_ex
*** 1885,1890 ****
--- 1885,1907 ----
? PREFIX("spread_char")
: PREFIX("spread"));
+ if (dim && gfc_is_constant_expr (dim)
+ && ncopies && gfc_is_constant_expr (ncopies)
+ && source->shape[0])
+ {
+ int i, idim;
+ idim = mpz_get_ui (dim->value.integer);
+ f->shape = gfc_get_shape (f->rank);
+ for (i = 0; i < (idim - 1); i++)
+ mpz_init_set (f->shape[i], source->shape[i]);
+
+ mpz_init_set (f->shape[idim - 1], ncopies->value.integer);
+
+ for (i = idim; i < f->rank ; i++)
+ mpz_init_set (f->shape[i], source->shape[i-1]);
+ }
+
+
gfc_resolve_dim_arg (dim);
gfc_resolve_index (ncopies, 1);
}
Index: gcc/testsuite/gfortran.dg/spread_shape_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/spread_shape_1.f90 (revision 0)
--- gcc/testsuite/gfortran.dg/spread_shape_1.f90 (revision 0)
***************
*** 0 ****
--- 1,20 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR29060 in which the shape of the result
+ ! of SPREAD was not available to the scalarizer.
+ !
+ ! Contributed by Paul Thomas <pault@gcc.gnu.org>
+ real,dimension(:, :),pointer :: ptr
+ real,dimension(2, 2),parameter :: u = &
+ reshape((/0.25, 0.5, 0.75, 1.00/),(/2,2/))
+ allocate (ptr(2,2))
+
+ ! Original PR
+ ptr(:, :) = u + spread ((/1.0, 2.0/), 2, size(u, 2))
+ if (any (ptr .ne. &
+ reshape ((/1.25, 2.50, 1.75, 3.00/), (/2, 2/)))) call abort ()
+
+ ! Check that the fix works correctly with the source shape after ncopies
+ ptr(:, :) = u + spread ((/2.0, 3.0/), 1, size (u, 1))
+ if (any (ptr .ne. &
+ reshape ((/2.25, 2.50, 3.75, 4.00/), (/2,2/)))) call abort ()
+ end
2006-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29060
* iresolve.c (resolve_spread): Build shape for result if the
source shape is available and dim and ncopies are constants.
2006-09-17 Paul Thomas <pault@gcc.gnu.org>
PR fortran/29060
* gfortran.dg/spread_shape_1.f90: New test.