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]

[gfortran] Fix PR 15234 : asseumed length character arrays


With patient coaching by Paul (thanks!), I managed to fix PR 15234.
There were two issues:
1. the length of an assumed length character string is not an integer
constant, but the calls to trans_init_string_length are only needed (and
right) in the case of automatic character strings, so that condition was
wrong. Fixed in the first two hunks.
2. we wouldn't pass the string length if we were pasing an array of
strings. This is fixed by the last two hunks. Unfortunately, the first
hunk (case where we need a temporary) remains untested, because we can't
ready to allocate temporary arrays of type character yet, that code is
not working.

Compiled and tested on i686-pc-linux.

- Tobi

2004-07-15  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/15234
	* trans-array.c gfc_trans_g77_array,
	gfc_trans_dummy_array_bias): Don't call gfc_trans_string_init
	for assumed length characters.
	(gfc_conv_expr_descriptor): Set se->string_length if dealing
	with a character expression.

Index: trans-array.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-array.c,v
retrieving revision 1.10
diff -u -p -r1.10 trans-array.c
--- trans-array.c       12 Jul 2004 01:23:36 -0000      1.10
+++ trans-array.c       15 Jul 2004 00:57:04 -0000
@@ -2947,7 +2947,7 @@ gfc_trans_g77_array (gfc_symbol * sym, t
   gfc_start_block (&block);

   if (sym->ts.type == BT_CHARACTER
-      && !INTEGER_CST_P (sym->ts.cl->backend_decl))
+      && TREE_CODE (sym->ts.cl->backend_decl) == VAR_DECL)
     gfc_trans_init_string_length (sym->ts.cl, &block);

   /* Evaluate the bounds of the array.  */
@@ -3026,7 +3026,7 @@ gfc_trans_dummy_array_bias (gfc_symbol *
   gfc_start_block (&block);

   if (sym->ts.type == BT_CHARACTER
-      && !INTEGER_CST_P (sym->ts.cl->backend_decl))
+      && TREE_CODE (sym->ts.cl->backend_decl) == VAR_DECL)
     gfc_trans_init_string_length (sym->ts.cl, &block);

   checkparm = (sym->as->type == AS_EXPLICIT && flag_bounds_check);
@@ -3390,7 +3390,12 @@ gfc_conv_expr_descriptor (gfc_se * se, g
       loop.temp_ss->type = GFC_SS_TEMP;
       loop.temp_ss->next = gfc_ss_terminator;
       loop.temp_ss->data.temp.type = gfc_typenode_for_spec (&expr->ts);
-      loop.temp_ss->data.temp.string_length = NULL;
+      /* Which can hold our string, if present.  */
+      if (expr->ts.type == BT_CHARACTER)
+       se->string_length = loop.temp_ss->data.temp.string_length
+         = TYPE_SIZE_UNIT (loop.temp_ss->data.temp.type);
+      else
+       loop.temp_ss->data.temp.string_length = NULL;
       loop.temp_ss->data.temp.dimen = loop.dimen;
       gfc_add_ss_to_loop (&loop, loop.temp_ss);
     }
@@ -3451,6 +3456,10 @@ gfc_conv_expr_descriptor (gfc_se * se, g
       tree to;
       tree base;

+      /* set the string_length for a character array.  */
+      if (expr->ts.type == BT_CHARACTER)
+       se->string_length = expr->symtree->n.sym->ts.cl->backend_decl;
+
       /* Otherwise make a new descriptor and point it at the section we
          want.  The loop variable limits will be the limits of the section.
        */


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