This is the mail archive of the gcc@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]

[Fortran] Conquering the last Frontier ...


L.S.,

Consider this C program:

#include <stdio.h>
main (){
   static float f[400000000];
   f[0] = 1.0;
   printf("%f\n",f[0]);
}

and its Fortran counterpart:

      program aap
      real a(400000000)
      a(1) = 1.0
      print*,a(1)
      end

Compiling the C program doesn't encounter any adverse effects:

toon@laptop:~/g77-bugs$ /usr/snp/bin/gcc large.c

However, the Fortran program elicits:

large.f: In program `aap':
large.f:2: 
         real a(400000000)
              ^
Array `a' at (^) is too large to handle

This can be explained by the conditions the C, resp. Fortran front end,
employ to determine whether an array is "too large", i.e., won't be
adequately addressed.

The C front end uses the following tests (c-decl.c:4476ff):

	if (tree_int_cst_sgn (size) < 0)
	{
		error ("size of array `%s' is negative", name);            			size =
integer_one_node;
	}

and

	/* Compute the maximum valid index, that is, size - 1.
	   Do the calculation in index_type, so that if it is
	   a variable the computations will be done in the
	   proper mode.  */
	itype = fold (build (MINUS_EXPR, index_type,
		 convert (index_type, size),
		 convert (index_type, size_one_node)));

	/* If that overflowed, the array is too big.
	   ??? While a size of INT_MAX+1 technically shouldn't
	   cause an overflow (because we subtract 1), the overflow
	   is recorded during the conversion to index_type, before
	   the subtraction.  Handling this case seems like an
	   unnecessary complication.  */
	if (TREE_OVERFLOW (itype))
	{
		error ("size of array `%s' is too large", name);           			type =
error_mark_node;
		continue;
	}

Whereas the Fortran front end uses (com.c:2268ff):

  if ((tree_int_cst_sgn (TYPE_SIZE (type)) < 0)
      || (!dummy && (((TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0))
                     || TREE_OVERFLOW (TYPE_SIZE (type)))))

[ !dummy isn't very interesting in this case - it's used for dummy
   arguments, whose size isn't know anyway. ]

Note the extra condition: TREE_INT_CST_HIGH (TYPE_SIZE (type)) != 0.
If I remove this, the Fortran code compiles as well.

So the 64K question is: Is this condition necessary, and if so, why -
and why isn't it present in the C front end ?

Thanks for any insight offered.

-- 
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG  Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)


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