From 80f2bb6e3af5a9ae2576f86258cdafa7fe1ff384 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 18 Sep 2006 06:24:54 +0000 Subject: [PATCH] re PR fortran/29060 (spread causes ICE in gfc_trans_array_constructor) 2006-09-18 Paul Thomas PR fortran/29060 * iresolve.c (resolve_spread): Build shape for result if the source shape is available and dim and ncopies are constants. PR fortran/28817 PR fortran/21918 * trans-decl.c (generate_local_decl): Change from 'warning' to 'gfc_warning' to have line numbers correctly reported. 2006-09-18 Paul Thomas PR fortran/29060 * gfortran.dg/spread_shape_1.f90: New test. From-SVN: r117014 --- gcc/fortran/ChangeLog | 13 +++++++++++++ gcc/fortran/iresolve.c | 17 +++++++++++++++++ gcc/fortran/trans-decl.c | 6 ++++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/spread_shape_1.f90 | 20 ++++++++++++++++++++ 5 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/spread_shape_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bf2c58deb11..04b8c8e79ca 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2006-09-18 Paul Thomas + + 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-18 Tobias Schlüter + + PR fortran/28817 + PR fortran/21918 + * trans-decl.c (generate_local_decl): Change from 'warning' to + 'gfc_warning' to have line numbers correctly reported. + 2006-09-15 Paul Thomas PR fortran/29051 diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index a9a98588c49..c72bf9f8b3f 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -1885,6 +1885,23 @@ gfc_resolve_spread (gfc_expr * f, gfc_expr * source, ? 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); } diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 855c98216c5..e4c5a5ae595 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -2883,12 +2883,14 @@ generate_local_decl (gfc_symbol * sym) if (sym->attr.referenced) gfc_get_symbol_decl (sym); else if (sym->attr.dummy && warn_unused_parameter) - warning (0, "unused parameter %qs", sym->name); + gfc_warning ("Unused parameter %s declared at %L", sym->name, + &sym->declared_at); /* Warn for unused variables, but not if they're inside a common block or are use-associated. */ else if (warn_unused_variable && !(sym->attr.in_common || sym->attr.use_assoc)) - warning (0, "unused variable %qs", sym->name); + gfc_warning ("Unused variable %s declared at %L", sym->name, + &sym->declared_at); /* For variable length CHARACTER parameters, the PARM_DECL already references the length variable, so force gfc_get_symbol_decl even when not referenced. If optimize > 0, it will be optimized diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ee17e194246..3311a54ef7a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-09-18 Paul Thomas + + PR fortran/29060 + * gfortran.dg/spread_shape_1.f90: New test. + 2006-09-17 Roger Sayle PR tree-optimization/28887 diff --git a/gcc/testsuite/gfortran.dg/spread_shape_1.f90 b/gcc/testsuite/gfortran.dg/spread_shape_1.f90 new file mode 100644 index 00000000000..c9f96f3661e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/spread_shape_1.f90 @@ -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 + 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