diff mbox

PR fortran/58989

Message ID 20131105170753.GA25908@troutmask.apl.washington.edu
State New
Headers show

Commit Message

Steve Kargl Nov. 5, 2013, 5:07 p.m. UTC
The inlined patch fixes a problem where an array constructor
is used as the shape argument in RESHAPE.  The patch is 
straightforward and self-explanatory.
Regression tested on x86_64-*-freebsd11
Ok?

2013-11-05  Steven G. Kargl <kargl@gcc.gnu.org>

	PR fortran/58989
	* check.c (gfc_check_reshape): ensure that shape is a constant
	expression.

2013-11-05  Steven G. Kargl <kargl@gcc.gnu.org>

	PR fortran/58989
	* gfortran.dg/reshape_6.f90: New test.

Comments

Paul Richard Thomas Nov. 5, 2013, 7:35 p.m. UTC | #1
Hi Steve,

It looks good to me - OK for trunk.

Thanks for the patch.

Paul

On 5 November 2013 18:07, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> The inlined patch fixes a problem where an array constructor
> is used as the shape argument in RESHAPE.  The patch is
> straightforward and self-explanatory.
> Regression tested on x86_64-*-freebsd11
> Ok?
>
> 2013-11-05  Steven G. Kargl <kargl@gcc.gnu.org>
>
>         PR fortran/58989
>         * check.c (gfc_check_reshape): ensure that shape is a constant
>         expression.
>
> 2013-11-05  Steven G. Kargl <kargl@gcc.gnu.org>
>
>         PR fortran/58989
>         * gfortran.dg/reshape_6.f90: New test.
>
>
> Index: gcc/fortran/check.c
> ===================================================================
> --- gcc/fortran/check.c (revision 204372)
> +++ gcc/fortran/check.c (working copy)
> @@ -3277,7 +3277,7 @@ gfc_check_reshape (gfc_expr *source, gfc
>                  "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
>        return false;
>      }
> -  else if (shape->expr_type == EXPR_ARRAY)
> +  else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
>      {
>        gfc_expr *e;
>        int i, extent;
> Index: gcc/testsuite/gfortran.dg/reshape_6.f90
> ===================================================================
> --- gcc/testsuite/gfortran.dg/reshape_6.f90     (revision 0)
> +++ gcc/testsuite/gfortran.dg/reshape_6.f90     (working copy)
> @@ -0,0 +1,19 @@
> +! { dg-do compile }
> +! PR fortran/58989
> +!
> +program test
> +
> +  real(8), dimension(4,4) :: fluxes
> +  real(8), dimension(2,2,2,2) :: f
> +  integer, dimension(3) :: dmmy
> +  integer, parameter :: indx(4)=(/2,2,2,2/)
> +
> +  fluxes = 1
> +
> +  dmmy = (/2,2,2/)
> +
> +  f = reshape(fluxes,(/dmmy,2/))  ! Caused an ICE
> +  f = reshape(fluxes,(/2,2,2,2/)) ! Works as expected
> +  f = reshape(fluxes,indx)        ! Works as expected
> +
> +end program test
> --
> Steve
diff mbox

Patch

Index: gcc/fortran/check.c
===================================================================
--- gcc/fortran/check.c	(revision 204372)
+++ gcc/fortran/check.c	(working copy)
@@ -3277,7 +3277,7 @@  gfc_check_reshape (gfc_expr *source, gfc
 		 "than %d elements", &shape->where, GFC_MAX_DIMENSIONS);
       return false;
     }
-  else if (shape->expr_type == EXPR_ARRAY)
+  else if (shape->expr_type == EXPR_ARRAY && gfc_is_constant_expr (shape))
     {
       gfc_expr *e;
       int i, extent;
Index: gcc/testsuite/gfortran.dg/reshape_6.f90
===================================================================
--- gcc/testsuite/gfortran.dg/reshape_6.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/reshape_6.f90	(working copy)
@@ -0,0 +1,19 @@ 
+! { dg-do compile }
+! PR fortran/58989
+!
+program test
+
+  real(8), dimension(4,4) :: fluxes
+  real(8), dimension(2,2,2,2) :: f
+  integer, dimension(3) :: dmmy 
+  integer, parameter :: indx(4)=(/2,2,2,2/)
+
+  fluxes = 1
+
+  dmmy = (/2,2,2/)
+
+  f = reshape(fluxes,(/dmmy,2/))  ! Caused an ICE
+  f = reshape(fluxes,(/2,2,2,2/)) ! Works as expected
+  f = reshape(fluxes,indx)        ! Works as expected
+
+end program test