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/36153 -- Fix complicationn due to KIND in SIZE


The attached patch fixes the problem in PR fortran/36153.
When FX added the F2003 arguments to several intrinsics,
he failed to recognize that resolve_function had special
code to detect the 2nd argument to SIZE (and incidentally
UBOUND).  This 2nd argument in F95 is DIM, which dealt with
differently than the F2003 KIND.  Thus, a loop not short
circuitly as should have been.

There is no testcase in that the original problematic 
code allocated more than 8 GB of memory.  This has dire
consequence on low memory machines.  A slight variation 
of the original code is

   program test_64
   implicit none
   integer, parameter :: long = selected_int_kind(18)
   integer, parameter :: short = kind(0)
   integer(long), parameter :: big_sz = huge(0_short)+1000_long
   integer, dimension(:), allocatable :: array
   integer(long) :: i
   allocate(array(big_sz))
   print *, "sz = ", size(array, kind=long)
   deallocate(array)
   end program

troutmask:sgk[265] gfc4x -o z a.f90
troutmask:sgk[266] ./z
 sz =            2147484647


2008-08-29  Steven G. Kargl  <kargls@comcast.net>

	PR fortran/36153
	* fortran/resolve.c (resolve_function): Shortcircuit for SIZE and
	UBOUND if 2nd argument is KIND.
-- 
Steve
Index: resolve.c
===================================================================
--- resolve.c	(revision 139774)
+++ resolve.c	(working copy)
@@ -2308,6 +2308,9 @@ resolve_function (gfc_expr *expr)
 	      if (arg->next->expr->expr_type != EXPR_CONSTANT)
 		break;
 
+	      if (strncmp(arg->next->name, "kind", 4) == 0)
+		break;
+
 	      if ((int)mpz_get_si (arg->next->expr->value.integer)
 			< arg->expr->rank)
 		break;

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