[rfc] Clobber scalar intent(out) variables on entry
diff mbox series

Message ID bffebc83-b442-4e00-c46b-137aff23bce8@tkoenig.net
State New
Headers show
Series
  • [rfc] Clobber scalar intent(out) variables on entry
Related show

Commit Message

Thomas K├Ânig Sept. 20, 2018, 7:29 p.m. UTC
Hi,

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

  }

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

Patch
diff mbox series

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);