This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, fortran] PR34556 Rejects valid with bogus error message: parameter initalization


Hi,

This was tricky to find. gfc_simplify_reshape was failing with the function MAX in an argument.

The attached patch fixes this problem by checking for EXPR_FUNCTION in the incoming array argument constructors. The gfc_get_array_element was failing when attempting to get an element using expand_constructor which can not expand or otherwise simplify the MAX intrinsic.

Regression tested on x86-64. New test case developed from the one in the PR.

OK for trunk?

Regards,

Jerry

2008-01-13 Jerry DeLisle <jvdelisle@gcc.gnu.org>

	PR fortran/34556
	* simplify.c (gfc_simplify_reshape): Add checks for expression type ==
	EXPR_FUNCTION in reshape array argument constructors.
Index: simplify.c
===================================================================
--- simplify.c	(revision 131492)
+++ simplify.c	(working copy)
@@ -3178,7 +3178,7 @@ gfc_simplify_reshape (gfc_expr *source, 
   size_t nsource;
   gfc_expr *e;
 
-  /* Unpack the shape array.  */
+  /* Check that argument expression types are OK.  */
   if (source->expr_type != EXPR_ARRAY || !gfc_is_constant_expr (source))
     return NULL;
 
@@ -3194,6 +3194,25 @@ gfc_simplify_reshape (gfc_expr *source, 
 	  || !gfc_is_constant_expr (order_exp)))
     return NULL;
 
+  /* Can not simplify here if incoming argument constructor is a function.  */
+  if (source->value.constructor
+      && source->value.constructor->expr->expr_type == EXPR_FUNCTION)
+    return NULL;
+
+  if (shape_exp->value.constructor
+      && shape_exp->value.constructor->expr->expr_type == EXPR_FUNCTION)
+    return NULL;
+  
+  if (pad != NULL && pad->value.constructor
+      && pad->value.constructor->expr->expr_type == EXPR_FUNCTION)
+    return NULL;
+  
+  if (order_exp != NULL && order_exp->value.constructor
+      && order_exp->value.constructor->expr->expr_type == EXPR_FUNCTION)
+    return NULL;
+
+  /* Proceed with simplification, unpacking the array.  */
+
   mpz_init (index);
   rank = 0;
   head = tail = NULL;
! { dg-do run }
! PR34556 Rejects valid with bogus error message: parameter initalization
! Found using the Fortran Company Fortran 90 Test Suite (Lite),
! Version 1.4
! Test case modified by Jerry DeLisle  <jvdelisle@gcc.gnu.org to
! show correct results.
module splitprms
      integer, parameter  :: nplam = 3 ! # of plans to expand TABs
      integer, parameter  :: linem = 132 ! max. line length
      integer, parameter  :: ncntm = 39 ! max. # cont. lines
      integer, parameter, dimension (linem, nplam) :: nxttab =  &
      reshape (                                                 &
               (/ max( (/ (6+3*((i-6+3)/3), i= 1,linem),        &
                          (6+2*((i-6+2)/2), i= 1,linem) /),     &
                       (/ (6, i= 1, 2*linem) /)            ),   &
                  (/                      (i, i= 1,linem) /) /),&
                (/ linem, nplam /) )
end module splitprms

program test
  use splitprms
  if (nxttab(1, 1) .ne. 6) call abort
  if (nxttab(1, nplam) .ne. 1) call abort
  if (nxttab(linem, 1) .ne. 135) call abort
  if (nxttab(linem, nplam) .ne. 132) call abort
end program test
! { dg-final { cleanup-modules "splitprms" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]