This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] Fix PR 36670, bounds check on product and sum
- From: Thomas Koenig <tkoenig at netcologne dot de>
- To: fortran at gcc dot gnu dot org
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 01 Jul 2008 21:18:22 +0200
- Subject: [patch, fortran] Fix PR 36670, bounds check on product and sum
Hello world,
this rather self-explanatory patch fixes the missing bounds check
on the product and sum intrinsics.
Regression-tested on i686-pc-linux-gnu.
OK for trunk?
Thomas
2008-07-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/36670
* iresolve.c (gfc_resolve_product): Set shape of return
value from array.
(gfc_resolve_sum): Likewise.
2008-07-01 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/36670
* gfortran.dg/product_sum_bounds_1.f90: New test case.
! { dg-do compile }
program main
real, dimension(4,3) :: a
real, dimension(2) :: b
a = 21.
b = product(a,dim=1) ! { dg-error "Different shape" }
b = sum(a,dim=2) ! { dg-error "Different shape" }
end program main
Index: /home/ig25/gcc/trunk/gcc/fortran/iresolve.c
===================================================================
--- /home/ig25/gcc/trunk/gcc/fortran/iresolve.c (revision 137255)
+++ /home/ig25/gcc/trunk/gcc/fortran/iresolve.c (working copy)
@@ -1788,6 +1788,7 @@ gfc_resolve_product (gfc_expr *f, gfc_ex
if (dim != NULL)
{
f->rank = array->rank - 1;
+ f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
gfc_resolve_dim_arg (dim);
}
@@ -2271,6 +2272,7 @@ gfc_resolve_sum (gfc_expr *f, gfc_expr *
if (dim != NULL)
{
f->rank = array->rank - 1;
+ f->shape = gfc_copy_shape_excluding (array->shape, array->rank, dim);
gfc_resolve_dim_arg (dim);
}