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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|2013-03-29 00:00:00         |2018-09-22
     Ever confirmed|0                           |1

--- Comment #3 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
I tried adding clobbers both on the caller's side and the
callee's side.

One problem was that with

Index: trans-decl.c
===================================================================
--- trans-decl.c        (Revision 264487)
+++ trans-decl.c        (Arbeitskopie)
@@ -47,6 +47,8 @@ along with GCC; see the file COPYING3.  If not see
 #include "gomp-constants.h"
 #include "gimplify.h"

+#include "print-tree.h"
+
 #define MAX_LABEL_VALUE 99999


@@ -4065,7 +4067,9 @@ gfc_init_default_dt (gfc_symbol * sym, stmtblock_t

 /* Initialize INTENT(OUT) derived type dummies.  As well as giving
    them their default initializer, if they do not have allocatable
-   components, they have their allocatable components deallocated.  */
+   components, they have their allocatable components deallocated.  Also,
+   this is used as a convenient place to clobber scalar INTENT(OUT)
+   variables on procedure entry.  */

 static void
 init_intent_out_dt (gfc_symbol * proc_sym, gfc_wrapped_block * block)
@@ -4143,6 +4147,25 @@ init_intent_out_dt (gfc_symbol * proc_sym, gfc_wra

        gfc_add_expr_to_block (&init, tmp);
       }
+    else if (!proc_sym->attr.elemental
+            && f->sym && f->sym->attr.dummy && f->sym->attr.intent ==
INTENT_OUT
+            && f->sym->attr.dimension == 0 && f->sym->attr.codimension == 0
+            && !f->sym->attr.allocatable && f->sym->ts.type != BT_CHARACTER
+            && f->sym->ts.type != BT_CLASS && f->sym->ts.type != BT_DERIVED)
+      {
+       tree var, clobber;
+       var = build_fold_indirect_ref_loc (input_location,
f->sym->backend_decl);
+       fprintf(stderr,"\nbackend_decl:\n");
+       debug_tree (f->sym->backend_decl);
+       fprintf(stderr,"\nvar:\n");
+       debug_tree (var);
+       fprintf(stderr,"\nDECL_SIZE(var)\n");
+       debug_tree (DECL_SIZE(var));
+       clobber = build_clobber (TREE_TYPE (var));
+       fprintf(stderr,"\nclobber:\n");
+       debug_tree (clobber);
+       gfc_add_modify (&init, var, clobber);
+      }

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

(minus the debuggin statements, if you want) I got ICEs during
gimplification if the procedure had contained procedures.
It appears that whatever build_fold_indirect_ref_loc from
a reference argument cannot be used because DECL_SIZE cannot
be used on var.

A failing test case for this would be

subroutine foo (outv)
  integer, intent(out) :: outv
contains
  subroutine bar
  end subroutine bar
end subroutine foo

I am not sure if this is a middle end bug, or that we are somehow
abusing something in the middle end.

Anyway, I will start by submiting the part that works.

Reply via email to