This is the mail archive of the gcc-bugs@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]

[Bug fortran/54070] Wrong code with allocatable deferred-length (array) function results


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54070

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-07-24 09:27:53 UTC ---
(In reply to comment #0)
> function f()
>   character(len=:),allocatable :: f
>   f ="ABC"
> end function

That part is solved via the following patch; I not yet sure whether I like the
patch or not.

--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -1228 +1228,2 @@ gfc_get_symbol_decl (gfc_symbol * sym)
-  if ((sym->attr.dummy && ! sym->attr.function) || (sym->attr.result &&
byref))
+  if ((sym->attr.dummy && ! sym->attr.function)
+      || (byref && (sym->attr.result || sym->result == sym)))
@@ -1254 +1255,2 @@ gfc_get_symbol_decl (gfc_symbol * sym)
-         if (sym->ts.deferred && sym->attr.result
+         if (sym->ts.deferred
+             && (sym->attr.result || sym->result == sym)


For some reason, the temporary does not seem to be needed when doing an
assignment of a variable, i.e.
  function f()
    character (len=*) :: a
    character(len=:),allocatable :: f
    f = a
  end function

 * * *

For arrays, I think the proper way is to store the length in the array
descriptor - as required for C interoperable strings in TR29113.

In any case, the array code doesn't use gfc_get_symbol_decl but invokes:
gfc_trans_deferred_vars -> (gfc_trans_dummy_array_bias,
gfc_trans_dummy_character), where the latter calls gfc_trans_vla_type_sizes.

In one of the latter procedures, one could insert some code to generate a local
length variable, which could then be put in the finally part as last argument
of the gfc_add_init_cleanup in gfc_trans_dummy_character. Or one might be able
to dereference the variable directly in se.string_len?


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