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: [Patch, fortran] PR34784 and PR34785 - array constructor "F95" problems


Tobias,

I got to the bottom of the character typing issue. The matcher was
trying to match a substring after a function reference.  If the type
was unknown, it was made character.  However, if the substring match
failed, it did not clear the character typing.

The other wrinkle is fixed, as shown in the ChangeLog - I encountered
this one before.

The testcases now reflect the extra issues that have been dealt with.

Bootstrapped and regtested on x86_ia64/FC8 - OK for trunk?

Cheers

Paul

2008-01-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34784
	* array.c (gfc_check_constructor_type): Clear the expression ts
	so that the checking starts from the deepest level of array
	constructor.
	* primary.c (match_varspec): If an unknown type is changed to
	default character and the attempt to match a substring fails,
	change it back to unknown.

	PR fortran/34785
	* trans-array.c (gfc_add_loop_ss_code) : If ss->string_length is
	NULL for an array constructor, use the cl.length expression to
	build it.
	(gfc_conv_array_parameter): Change call to gfc_evaluate_now to
	a tree assignment.


2008-01-19  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/34784
	* gfortran.dg/array_constructor_20.f90: New test.
	* gfortran.dg/mapping_2.f90: Correct ubound expression for h4.

	PR fortran/34785
	* gfortran.dg/array_constructor_21.f90: New test.
Index: gcc/fortran/trans-array.c
===================================================================
--- gcc/fortran/trans-array.c	(revision 131611)
+++ gcc/fortran/trans-array.c	(working copy)
@@ -1906,6 +1906,18 @@
 	  break;
 
 	case GFC_SS_CONSTRUCTOR:
+	  if (ss->expr->ts.type == BT_CHARACTER
+		&& ss->string_length== NULL
+		&& ss->expr->ts.cl
+		&& ss->expr->ts.cl->length)
+	    {
+	      gfc_init_se (&se, NULL);
+	      gfc_conv_expr_type (&se, ss->expr->ts.cl->length,
+				  gfc_charlen_type_node);
+	      ss->string_length = se.expr;
+	      gfc_add_block_to_block (&loop->pre, &se.pre);
+	      gfc_add_block_to_block (&loop->post, &se.post);
+	    }
 	  gfc_trans_array_constructor (loop, ss);
 	  break;
 
@@ -5042,7 +5054,7 @@
     {
       get_array_ctor_strlen (&se->pre, expr->value.constructor, &tmp);
       expr->ts.cl->backend_decl = tmp;
-      se->string_length = gfc_evaluate_now (tmp, &se->pre);
+      se->string_length = tmp;
     }
 
   /* Is this the result of the enclosing procedure?  */
Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 131611)
+++ gcc/fortran/array.c	(working copy)
@@ -1025,6 +1025,7 @@
 
   cons_state = CONS_START;
   gfc_clear_ts (&constructor_ts);
+  gfc_clear_ts (&e->ts);
 
   t = check_constructor_type (e->value.constructor);
   if (t == SUCCESS && e->ts.type == BT_UNKNOWN)
Index: gcc/fortran/primary.c
===================================================================
--- gcc/fortran/primary.c	(revision 131611)
+++ gcc/fortran/primary.c	(working copy)
@@ -1676,6 +1676,7 @@
   gfc_component *component;
   gfc_symbol *sym = primary->symtree->n.sym;
   match m;
+  bool unknown;
 
   tail = NULL;
 
@@ -1753,12 +1754,14 @@
     }
 
 check_substring:
+  unknown = false;
   if (primary->ts.type == BT_UNKNOWN)
     {
       if (gfc_get_default_type (sym, sym->ns)->type == BT_CHARACTER)
        {
 	 gfc_set_default_type (sym, 0, sym->ns);
 	 primary->ts = sym->ts;
+	 unknown = true;
        }
     }
 
@@ -1781,6 +1784,8 @@
 	  break;
 
 	case MATCH_NO:
+	  if (unknown)
+	    gfc_clear_ts (&primary->ts);
 	  break;
 
 	case MATCH_ERROR:
Index: gcc/testsuite/gfortran.dg/array_constructor_20.f90
===================================================================
--- gcc/testsuite/gfortran.dg/array_constructor_20.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/array_constructor_20.f90	(revision 0)
@@ -0,0 +1,22 @@
+! { dg-do compile }
+!
+! PR fortran/34784, in which the intrinsic expression would be
+! given the implicit type.
+!
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+!
+MODULE m
+  implicit character(s)
+  INTEGER :: I(1) = (/ (SELECTED_INT_KIND(J),J=1,1) /)
+END MODULE m
+
+MODULE s_TESTS
+  IMPLICIT CHARACTER (P)
+CONTAINS
+  subroutine simple (u,j1)
+    optional ::  j1
+    if (present (j1)) stop
+  end subroutine
+END MODULE s_TESTS
+
+! { dg-final { cleanup-modules "m s_TESTS" } }
Index: gcc/testsuite/gfortran.dg/array_constructor_21.f90
===================================================================
--- gcc/testsuite/gfortran.dg/array_constructor_21.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/array_constructor_21.f90	(revision 0)
@@ -0,0 +1,36 @@
+! { dg-do compile }
+!
+! PR fortran/34785, in which the character length of BA_T was not
+! passed on to the array constructor argument of SEQ.
+!
+! Contributed by Dick Hendrickson <dick.hendrickson@gmail.com>
+!
+      MODULE o_TYPE_DEFS
+        implicit none
+        TYPE SEQ
+          SEQUENCE
+          CHARACTER(len = 9) ::  BA(2)
+        END TYPE SEQ
+        CHARACTER(len = 9)   ::  BA_T(2)
+        CHARACTER(LEN = 9)   ::  CA_T(1,2)
+      END MODULE o_TYPE_DEFS
+
+      MODULE TESTS
+        use o_type_defs
+        implicit none
+      CONTAINS
+        SUBROUTINE OG0015(UDS0L)
+          TYPE(SEQ)          UDS0L
+          integer :: j1
+          UDS0L = SEQ((/ (BA_T(J1),J1=1,2) /))
+        END SUBROUTINE
+      END MODULE TESTS
+
+      use o_type_defs
+      CONTAINS
+        SUBROUTINE OG0015(UDS0L)
+          TYPE(SEQ)          UDS0L
+          UDS0L = SEQ(RESHAPE ( (/ ((CA_T(J1,J2), J1 = 1, 1), J2 = 1, 2)/),(/2/)))
+        END SUBROUTINE
+      END
+! { dg-final { cleanup-modules "o_TYPE_DEFS TESTS" } }
Index: gcc/testsuite/gfortran.dg/mapping_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/mapping_2.f90	(revision 131611)
+++ gcc/testsuite/gfortran.dg/mapping_2.f90	(working copy)
@@ -11,7 +11,7 @@
       function my_string(x)
          integer i
          real, intent(in) :: x(:)
-         character(0) h4(1:minval([(1,i=1,0)],1))
+         character(0) h4(1:minval([(i,i=30,32)],15))
          character(0) sv1(size(x,1):size(h4))
          character(0) sv2(2*lbound(sv1,1):size(h4))
          character(lbound(sv2,1)-3) my_string

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