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] Fix PR 44693


Hello world,

the attached patch fixes PR 44693.

During regression-testing, there was a failure of
dynamic_dispatch_6.f03 at higher optimization levels.  I *think* that
this is not related to this patch, but I would appreciate if the
reviewer would check for that.  Of course, if this turns out to really
cause a regression or expose a latent bug, I don't want to commit this.

OK for trunk?

	Thomas

2010-07-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/PR44693
	* check.c (dim_rank_check):  Also check intrinsic functions.
	Adjust permissible rank for functions which reduce the rank of
	their argument.

	PR fortran/PR44693
	* dim_range_1.f90:  New test.

Index: check.c
===================================================================
--- check.c	(Revision 161784)
+++ check.c	(Arbeitskopie)
@@ -473,12 +473,34 @@ dim_rank_check (gfc_expr *dim, gfc_expr *array, in
   if (dim == NULL)
     return SUCCESS;
 
-  if (dim->expr_type != EXPR_CONSTANT
-      || (array->expr_type != EXPR_VARIABLE
-	  && array->expr_type != EXPR_ARRAY))
+  if (dim->expr_type != EXPR_CONSTANT)
     return SUCCESS;
 
-  rank = array->rank;
+  if (array->expr_type == EXPR_FUNCTION && array->value.function.isym)
+    {
+
+      /* Functions which reduce the rank of their arguments.  */
+      switch(array->value.function.isym->id)
+	{
+	case GFC_ISYM_SUM:
+	case GFC_ISYM_PRODUCT:
+	case GFC_ISYM_ANY:
+	case GFC_ISYM_ALL:
+	case GFC_ISYM_COUNT:
+	case GFC_ISYM_MINVAL:
+	case GFC_ISYM_MAXVAL:
+	  rank = array->rank + 1;
+	  break;
+
+	default:
+	  rank = array->rank;
+	}
+    }
+  else
+    {
+      rank = array->rank;
+    }
+
   if (array->expr_type == EXPR_VARIABLE)
     {
       ar = gfc_find_array_ref (array);
! { dg-do compile }
! PR 44693 - check for invalid dim even in functions.
! Contributed by Dominique d'Humieres 
subroutine test1(esss,Ix,Iyz)
  real(kind=kind(1.0d0)), dimension(:), intent(out) :: esss
  real(kind=kind(1.0d0)), dimension(:,:) :: Ix,Iyz
  esss = sum(Ix * Iyz, 0) ! { dg-error "is not a valid dimension index" }
end subroutine

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