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] PATCH: Fix omitted optional CHARACTER arguments



This patch fixes the problem that we didn't generate the hidden string length arguments for omitted optional arguments to intrinsics. This patch is inspired from Andy's tree, but the implementation is mine.


What it does is that it adds a field to gfc_actual_arglist, where we record the type of omitted arguments. If we encounter a leftout optional argument, which would have been of type string we add an element for the strlen_type value zero to the function call.

(If intrinsics had a formal_arglist this could be handled much simpler, but it was decided that they shouldn't, I believe because they have to be able to deal with arguments of different types.)

Built and tested on i686-pc-linux with no regressions. The date_and_time implementation I sent earlier now works.

- Tobi

2004-06-03 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>

	* gfortran.h (gfc_actual_arglist): New field missing_arg_type.
	* interface.c (compare_actual_formal): Keep type of omitted
	optional arguments.
	* trans-expr.c (gfc_conv_function_call): Add string length
	argument for omitted string argument.

Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.10
diff -u -p -r1.10 gfortran.h
--- gfortran.h  1 Jun 2004 12:12:58 -0000       1.10
+++ gfortran.h  3 Jun 2004 18:02:18 -0000
@@ -538,6 +538,8 @@ typedef struct gfc_actual_arglist
   /* Alternate return label when the expr member is null.  */
   struct gfc_st_label *label;

+  bt missing_arg_type;
+
   struct gfc_expr *expr;
   struct gfc_actual_arglist *next;
 }
Index: interface.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/interface.c,v
retrieving revision 1.4
diff -u -p -r1.4 interface.c
--- interface.c 27 May 2004 12:35:12 -0000      1.4
+++ interface.c 3 Jun 2004 18:02:22 -0000
@@ -1291,6 +1293,11 @@ compare_actual_formal (gfc_actual_arglis
   if (*ap == NULL && n > 0)
     *ap = new[0];

+  /* Note the types of omitted optional arguments.  */
+  for (a = actual, f = formal; a; a = a->next, f = f->next)
+    if (a->expr == NULL && a->label == NULL)
+      a->missing_arg_type = f->sym->ts.type;
+
   return 1;
 }

Index: trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.7
diff -u -p -r1.7 trans-expr.c
--- trans-expr.c        30 May 2004 14:37:24 -0000      1.7
+++ trans-expr.c        3 Jun 2004 18:02:22 -0000
@@ -1077,7 +1077,7 @@ gfc_conv_function_call (gfc_se * se, gfc
              /* Pass a NULL pointer for an absent arg.  */
              gfc_init_se (&parmse, NULL);
              parmse.expr = null_pointer_node;
-              if (formal && formal->sym->ts.type == BT_CHARACTER)
+              if (arg->missing_arg_type == BT_CHARACTER)
                 {
                   stringargs = gfc_chainon_list (stringargs,
                       convert (gfc_strlen_type_node, integer_zero_node));


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