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] PR31011 - Incorrect error: parameter array sections


:ADDPATCH fortran:

This PR arises because the arithmetic for calculating section lengths
in expr.c(find_array_section) was plain and simple wrong.  I do not
want to investigate when this error was made because I suspect that I
was the culprit, when I wrote the function:)

In the present trunk, the length is calculated as:

length = (end - start + abs(stride)/stride)/stride

This fails for the section (1:3:2) in the reporter's example.  Change
the 3 to 4 and the correct result is obtained.

I have corrected the calculation to:

length = (end -start + stride)/stride

This has the gratifying property that it gives the correct result.

The attached testcase is a slight modification of the reporter's.

Bootstrapped and regtested on x86_ia64/FC5

OK for trunk and 4.2, in the fullness of time?

Paul

2007-03-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/31011
	* expr.c (find_array_section): Correct arithmetic for section
	size.

2007-03-08 Paul Thomas <pault@gcc.gnu.org>

	PR fortran/31011
	* gfortran.dg/parameter_array_section_2.f90: New test.


Winston Churchill: "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals."
Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c	(revision 122629)
--- gcc/fortran/expr.c	(working copy)
*************** find_array_section (gfc_expr *expr, gfc_
*** 1137,1144 ****
  	    }
  
  	  /* Calculate the number of elements and the shape.  */
! 	  mpz_abs (tmp_mpz, stride[d]);
! 	  mpz_div (tmp_mpz, stride[d], tmp_mpz);
  	  mpz_add (tmp_mpz, end[d], tmp_mpz);
  	  mpz_sub (tmp_mpz, tmp_mpz, ctr[d]);
  	  mpz_div (tmp_mpz, tmp_mpz, stride[d]);
--- 1137,1143 ----
  	    }
  
  	  /* Calculate the number of elements and the shape.  */
! 	  mpz_set (tmp_mpz, stride[d]);
  	  mpz_add (tmp_mpz, end[d], tmp_mpz);
  	  mpz_sub (tmp_mpz, tmp_mpz, ctr[d]);
  	  mpz_div (tmp_mpz, tmp_mpz, stride[d]);

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