public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, rfc] Clobber scalar intent(out) variables on entry
@ 2018-09-20 19:29 Thomas König
  0 siblings, 0 replies; only message in thread
From: Thomas König @ 2018-09-20 19:29 UTC (permalink / raw)
  To: fortran, gcc-patches

Hi,

the patch below tries to clobber scalar intent(out) arguments
on procedure entry.

Index: trans-decl.c
===================================================================
--- trans-decl.c        (Revision 264423)
+++ trans-decl.c        (Arbeitskopie)
@@ -4143,6 +4143,19 @@ init_intent_out_dt (gfc_symbol * proc_sym, gfc_wra

         gfc_add_expr_to_block (&init, tmp);
        }
+    else if (f->sym->attr.dummy && !f->sym->attr.dimension
+            && f->sym->attr.intent == INTENT_OUT
+            && !f->sym->attr.codimension && !f->sym->attr.allocatable
+            && (f->sym->ts.type != BT_CLASS
+                || (!CLASS_DATA (f->sym)->attr.dimension
+                    && !(CLASS_DATA (f->sym)->attr.codimension
+                         && CLASS_DATA (f->sym)->attr.allocatable))))
+      {
+       tree t1, t2;
+       t1 = build_fold_indirect_ref_loc (input_location, 
f->sym->backend_decl);
+       t2 = build_clobber (TREE_TYPE (t1));
+       gfc_add_modify (&init, t1, t2);
+      }

    gfc_add_init_cleanup (block, gfc_finish_block (&init), NULL_TREE);
  }

With this patch,

module x
   contains
     subroutine foo(a)
       real, intent(out) :: a
       a =  21.
       a = a + 22.
     end subroutine foo
end module x

generates, with -fdump-tree-original

foo (real(kind=4) & restrict a)
{
   *a = {CLOBBER};
   *a = 2.1e+1;
   *a = *a + 2.2e+1;
}

Is this the right way to proceed?

(The if statement is not yet correct, so this version causes
regressions, that would have to be adjusted).

Regards

	Thomas

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-09-20 19:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-20 19:29 [patch, rfc] Clobber scalar intent(out) variables on entry Thomas König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).