]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Avoid var initialization in interfaces [PR54753]
authorTobias Burnus <tobias@codesourcery.com>
Mon, 4 Oct 2021 07:41:13 +0000 (09:41 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 4 Oct 2021 07:41:13 +0000 (09:41 +0200)
Intent(out) implies deallocation/default initialization; however, it is
pointless to do this for dummy-arguments symbols of procedures which are
inside an INTERFACE block. – This also fixes a bogus error for the attached
included testcase, but fixing the non-interface version still has to be done.

PR fortran/54753

gcc/fortran/ChangeLog:

* resolve.c (can_generate_init, resolve_fl_variable_derived,
resolve_symbol): Only do initialization with intent(out) if not
inside of an interface block.

(cherry picked from commit 51d9ef7747b2dc439f7456303f0784faf5cdb1d3)

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/assumed_rank_23.f90 [new file with mode: 0644]
libgomp/ChangeLog.omp

index a7de91c6b3117f4a8aaf588c57123912a88d1855..1832730d20fb274107fc60049a4b253c5c79336c 100644 (file)
@@ -12677,7 +12677,8 @@ can_generate_init (gfc_symbol *sym)
     || a->cray_pointer
     || sym->assoc
     || (!a->referenced && !a->result)
-    || (a->dummy && a->intent != INTENT_OUT)
+    || (a->dummy && (a->intent != INTENT_OUT
+                    || sym->ns->proc_name->attr.if_source == IFSRC_IFBODY))
     || (a->function && sym != sym->result)
   );
 }
@@ -12914,7 +12915,9 @@ resolve_fl_variable_derived (gfc_symbol *sym, int no_init_flag)
 
   /* Assign default initializer.  */
   if (!(sym->value || sym->attr.pointer || sym->attr.allocatable)
-      && (!no_init_flag || sym->attr.intent == INTENT_OUT))
+      && (!no_init_flag
+         || (sym->attr.intent == INTENT_OUT
+             && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY)))
     sym->value = gfc_generate_initializer (&sym->ts, can_generate_init (sym));
 
   return true;
@@ -16155,7 +16158,8 @@ resolve_symbol (gfc_symbol *sym)
                    || sym->ts.u.derived->attr.alloc_comp
                    || sym->ts.u.derived->attr.pointer_comp))
           && !(a->function && sym != sym->result))
-         || (a->dummy && a->intent == INTENT_OUT && !a->pointer))
+         || (a->dummy && !a->pointer && a->intent == INTENT_OUT
+             && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY))
        apply_default_init (sym);
       else if (a->function && sym->result && a->access != ACCESS_PRIVATE
               && (sym->ts.u.derived->attr.alloc_comp
@@ -16167,6 +16171,7 @@ resolve_symbol (gfc_symbol *sym)
 
   if (sym->ts.type == BT_CLASS && sym->ns == gfc_current_ns
       && sym->attr.dummy && sym->attr.intent == INTENT_OUT
+      && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY
       && !CLASS_DATA (sym)->attr.class_pointer
       && !CLASS_DATA (sym)->attr.allocatable)
     apply_default_init (sym);
diff --git a/gcc/testsuite/gfortran.dg/assumed_rank_23.f90 b/gcc/testsuite/gfortran.dg/assumed_rank_23.f90
new file mode 100644 (file)
index 0000000..c83aa7d
--- /dev/null
@@ -0,0 +1,16 @@
+! { dg-do compile }
+!
+! PR fortran/54753
+! TS29113:C535c
+! F2018:C839
+!
+module m
+
+  interface
+    subroutine s1 (x, y)
+      class(*) :: x(..)
+      class(*), intent (out) :: y(..)
+    end subroutine
+  end interface
+
+end module 
index ca5014c3993c36fa040ee045eb627a2e3b971ffb..9d1afda94da302df0b7eaf2f03223b07b0664b3b 100644 (file)
@@ -1,3 +1,13 @@
+2021-10-04  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backported from master:
+       2021-10-04  Tobias Burnus  <tobias@codesourcery.com>
+
+       * testsuite/libgomp.fortran/order-reproducible-1.f90: New test
+       based on libgomp.c-c++-common/order-reproducible-1.c.
+       * testsuite/libgomp.fortran/order-reproducible-2.f90: Likewise.
+       * testsuite/libgomp.fortran/my-usleep.c: New test.
+
 2021-10-02  Tobias Burnus  <tobias@codesourcery.com>
 
        Backported from master: