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 PR15326


I forgot the standard's terminology, but this bug had to do with character
functions whose length depends on their arguments values, see attached
testcase. The compiler did the right thing already, only we didn't deal with
it correctly when building the function call.

Fixed as below, built and tested. New testcase attached. OK?

- Tobi

2004-09-25  Tobias Schlueter  <tobias.schlueter@physik.uni-muenchen.de>

	PR fortran/15326
	* trans-expr.c (gfc_conv_function_call): Use previously preexisting 	
	backend_decl, if present.

Index: trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.29
diff -u -p -r1.29 trans-expr.c
--- trans-expr.c        24 Sep 2004 17:06:55 -0000      1.29
+++ trans-expr.c        25 Sep 2004 14:55:02 -0000
@@ -1054,11 +1054,15 @@ gfc_conv_function_call (gfc_se * se, gfc
        }
       else if (sym->ts.type == BT_CHARACTER)
        {
-         gcc_assert (sym->ts.cl && sym->ts.cl->length
-                 && sym->ts.cl->length->expr_type == EXPR_CONSTANT);
-         len = gfc_conv_mpz_to_tree
-           (sym->ts.cl->length->value.integer, sym->ts.cl->length->ts.kind);
-         sym->ts.cl->backend_decl = len;
+         len = sym->ts.cl->backend_decl;
+         if (!len)
+           {
+             gcc_assert (sym->ts.cl && sym->ts.cl->length
+                         && sym->ts.cl->length->expr_type == EXPR_CONSTANT);
+             len = gfc_conv_mpz_to_tree (sym->ts.cl->length->value.integer,
+                                         sym->ts.cl->length->ts.kind);
+             sym->ts.cl->backend_decl = len;
+           }
          type = gfc_get_character_type (sym->ts.kind, sym->ts.cl);
          type = build_pointer_type (type);

! { dg-do run }
! we didn't deal correctly with functions whose lengths depends on
! their arguments
implicit none
character (len = 10) :: T1, T2
T1 = ""
if (LEN(decap(T1)).NE.10) call abort
T2 = D (T1)
if (t1.ne."          ") call abort
if (t2.ne."1234567890") call abort
contains
  function D (String)
    character (len = *), intent(in) :: String
    character (len = Len(String)) :: D
    D = "1234567890"
    return
  end function D
end

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