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]

Re: [Fortran, Patch] PR31188 - Allow array dummy as range for constant arrays


Hi,

FX Coudert wrote:
>> I would argue that SUCCESS is a bit cleaner conceptually, but FAILURE is
>> cleaner in terms of the code.
> From what I understood of the overall design, simplifying functions
> usually return NULL or FAILURE when they don't simplify, don't they?
I think some do, some don't. (AR_ELEMENT in gfc_simplify_expr is an
example for returning SUCCESS.)

The overall implementation is in any case not in line with the comments:

Comment above gfc_simplify_expr:
Returns FAILURE on error, SUCCESS otherwise.
NOTE: Will return SUCCESS even if the expression can not be simplified. */

To quote Paul:

"Returning SUCCESS is more consistent with the comment at the head of
gfc_simplify_expr. Returning FAILURE is consistent with extensive
malpractice throughout this part of expr.c and is simpler. You pay your
penny and make your choice. It's your call, since you got there first!
I'll OK either."

Given that FX prefers the simpler version and that expr.c is already
inconsistent, I decided to use Paul's version.

For completeness: Is the following patch ok?

Tobias
2007-03-15  Paul Thomas  <pault@gcc.gnu.org>
	    Tobias Burnus  <burnus@net-b.de>

	PR fortran/31188
	* expr.c (find_array_section): Allow
	  non-expression-constant variables.

2007-03-15  Tobias Burnus  <burnus@net-b.de>

	PR fortran/31188
	* gfortran.dg/parameter_array_dummy.f90: New test.

Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c	(revision 122979)
--- gcc/fortran/expr.c	(working copy)
*************** find_array_section (gfc_expr *expr, gfc_
*** 1063,1069 ****
        if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR)  /* Vector subscript.  */
  	{
  	  gcc_assert (begin);
! 	  gcc_assert (begin->expr_type == EXPR_ARRAY); 
  	  gcc_assert (begin->rank == 1);
  	  gcc_assert (begin->shape);
  
--- 1063,1075 ----
        if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR)  /* Vector subscript.  */
  	{
  	  gcc_assert (begin);
! 
! 	  if (begin->expr_type != EXPR_ARRAY)
! 	    {
! 	      t = FAILURE;
! 	      goto cleanup;
! 	    }
! 
  	  gcc_assert (begin->rank == 1);
  	  gcc_assert (begin->shape);
  
Index: gcc/testsuite/gfortran.dg/parameter_array_dummy.f90
===================================================================
*** gcc/testsuite/gfortran.dg/parameter_array_dummy.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/parameter_array_dummy.f90	(revision 0)
***************
*** 0 ****
--- 1,21 ----
+ ! { dg-do run}
+ ! PR fortran/31188
+ program foo_mod
+   implicit none
+   character (len=1), parameter :: letters(2) = (/"a","b"/)
+   call concat(1, [1])
+   call concat(2, [2])
+   call concat(3, [1,2])
+   call concat(4, [2,1])
+   call concat(5, [2,2,2])
+ contains
+   subroutine concat(i, ivec)
+     integer, intent(in)  :: i, ivec(:)
+     write (*,*) i, "a" // letters(ivec)
+   end subroutine concat
+ end program foo_mod
+ ! { dg-output "1 aa" }
+ ! { dg-output "2 ab" }
+ ! { dg-output "3 aaab" }
+ ! { dg-output "4 abaa" }
+ ! { dg-output "5 ababab" }

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