https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69423

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to vehre from comment #6)
> What I have learnt so far:
> 
> When the gimple optimisation algorithm 'remove_unused_locals ()' in
> gcc/tree-ssa-live.c is done, it has removed the temporary for the
> _gfortran_transfer_character_write's string length. In the previous analysis
> step this (ssa-)temporary has the uid 3471 in my current fortran. That var
> occurs in two basicblocks (bb), once in <bb 5> of ssa, where it is only used
> to check whether a preallocated incoming string has the correct length. That
> whole bb can be eliminated, because it is unreachable which can be deduced
> from the propagated attributes. But in the <bb 11> it must not be eliminated
> as well. Because in both bbs the uid of the temporary is the same, I tried
> several ways to prevent this association (adding a further temporary using
> gfc_evaluate_now (), copying the tree using copy_node ()), but to no avail
> yet. 
> 
> Having said this my assumption is, that at both occurrences of .__result_4
> the exactly same tree is used (and not a separate copy in each place). Maybe
> this is the issue, but I am still investigating. Just thought to let you
> know whether anything of this rings a bell.

Andre,

You have gone further in the diagnosis than I have. However, I would take a
look at comment #3. There is no reason at all why gimple should treat explicit
and implicit result variables differently. I THINK that the difference must lie
in the dead wood that I left in place in trans-decl.c(gfc_get_symbol_decl).

(A few minutes later) I just removed the whole lot and this did not fix this
PR. However, unsurprisingly, it does regtest OK, which tells me that the whole
lot should go.

I still can see absolutely no difference in the generated code.

Index: /svn/trunk/gcc/fortran/trans-decl.c
===================================================================
*** /svn/trunk/gcc/fortran/trans-decl.c (revision 233015)
--- /svn/trunk/gcc/fortran/trans-decl.c (working copy)
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 1366,1386 ****
        }
      }

-   /* All deferred character length procedures need to retain the backend
-      decl, which is a pointer to the character length in the caller's
-      namespace and to declare a local character length.  */
-   if (!byref && sym->attr.function
-       && sym->ts.type == BT_CHARACTER
-       && sym->ts.deferred
-       && sym->ts.u.cl->passed_length == NULL
-       && sym->ts.u.cl->backend_decl
-       && TREE_CODE (sym->ts.u.cl->backend_decl) == PARM_DECL)
-     {
-       sym->ts.u.cl->passed_length = sym->ts.u.cl->backend_decl;
-       gcc_assert (POINTER_TYPE_P (TREE_TYPE (sym->ts.u.cl->passed_length)));
-       sym->ts.u.cl->backend_decl = build_fold_indirect_ref
(sym->ts.u.cl->backend_decl);
-     }
- 
    fun_or_res = byref && (sym->attr.result
                         || (sym->attr.function && sym->ts.deferred));
    if ((sym->attr.dummy && ! sym->attr.function) || fun_or_res)
--- 1366,1371 ----
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 1409,1447 ****
             (sym->ts.u.cl->passed_length == sym->ts.u.cl->backend_decl))
            sym->ts.u.cl->backend_decl = NULL_TREE;

-         if (sym->ts.deferred && byref)
-           {
-             /* The string length of a deferred char array is stored in the
-                parameter at sym->ts.u.cl->backend_decl as a reference and
-                marked as a result.  Exempt this variable from generating a
-                temporary for it.  */
-             if (sym->attr.result)
-               {
-                 /* We need to insert a indirect ref for param decls.  */
-                 if (sym->ts.u.cl->backend_decl
-                     && TREE_CODE (sym->ts.u.cl->backend_decl) == PARM_DECL)
-                   {
-                     sym->ts.u.cl->passed_length = sym->ts.u.cl->backend_decl;
-                     sym->ts.u.cl->backend_decl =
-                       build_fold_indirect_ref (sym->ts.u.cl->backend_decl);
-                   }
-               }
-             /* For all other parameters make sure, that they are copied so
-                that the value and any modifications are local to the routine
-                by generating a temporary variable.  */
-             else if (sym->attr.function
-                      && sym->ts.u.cl->passed_length == NULL
-                      && sym->ts.u.cl->backend_decl)
-               {
-                 sym->ts.u.cl->passed_length = sym->ts.u.cl->backend_decl;
-                 if (POINTER_TYPE_P (TREE_TYPE (sym->ts.u.cl->passed_length)))
-                   sym->ts.u.cl->backend_decl
-                       = build_fold_indirect_ref (sym->ts.u.cl->backend_decl);
-                 else
-                   sym->ts.u.cl->backend_decl = NULL_TREE;
-               }
-           }
- 
          if (sym->ts.u.cl->backend_decl == NULL_TREE)
            length = gfc_create_string_length (sym);
          else
--- 1394,1399 ----

Cheers

Paul

Reply via email to