public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <burnus@net-b.de>
To: Sandra Loosemore <sandra@codesourcery.com>,
	Tobias Burnus <tobias@codesourcery.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>, Harald Anlauf <anlauf@gmx.de>
Subject: Re: [Patch] Fortran: Avoid var initialization in interfaces [PR54753]
Date: Sat, 2 Oct 2021 21:56:52 +0200	[thread overview]
Message-ID: <185251be-e866-4d5e-0deb-944940cd5511@net-b.de> (raw)
In-Reply-To: <bb8cefcd-7bd5-fdb6-54c8-567fb19f4a1c@net-b.de>

[-- Attachment #1: Type: text/plain, Size: 1051 bytes --]

Hi Harald,

unfortunately, your email did not arrive at fortran@gcc.gnu.org – nor at my private address.

I copied it from https://gcc.gnu.org/pipermail/gcc-patches/2021-October/580794.html

You wrote:
> >/I do not see this error. Can you double check that you indeed use the />/posted patch: />//>/https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580483.html 
> <https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580483.html> – />/and nothing else, e.g., an earlier draft? /
> Sandra is right.  Actually I do see that regression, too.
> The default initialization is missing in F1, see dump-tree:
Look as if I had attached the first/interim version of the patch –
which lacked what I wrote in the patch submission at:
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580483.html

Namely, I wrote:
> Regarding the patch, '!= IFSRC_IFBODY' has to be used; "== IFSRC_DECL"
> won't work as the the generatedy ENTRY master function has IFSRC_UNKNOWN.
Thus, no surprise that it passes here – while you see the fail.

Tobias


[-- Attachment #2: intent-out.diff --]
[-- Type: text/x-patch, Size: 3193 bytes --]

Fortran: Avoid var initialization in interfaces [PR54753]

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.

gcc/testsuite/ChangeLog:

	* gfortran.dg/assumed_rank_23.f90: New test.

 gcc/fortran/resolve.c                         | 11 ++++++++---
 gcc/testsuite/gfortran.dg/assumed_rank_23.f90 | 16 ++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 30b96b2f597..511fe3a5e55 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12676,7 +12676,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)
   );
 }
@@ -12913,7 +12914,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;
@@ -16154,7 +16157,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
@@ -16166,6 +16170,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
index 00000000000..c83aa7de1a3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/assumed_rank_23.f90
@@ -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 

  parent reply	other threads:[~2021-10-02 19:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  8:53 Tobias Burnus
2021-09-29 20:10 ` Harald Anlauf
2021-10-01 18:50 ` Harald Anlauf
2021-10-02 18:01 ` Sandra Loosemore
2021-10-02 18:29   ` Tobias Burnus
2021-10-02 19:19     ` Harald Anlauf
2021-10-02 19:56     ` Tobias Burnus [this message]
2021-10-02 20:28       ` Harald Anlauf
2021-10-02 22:40         ` Sandra Loosemore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=185251be-e866-4d5e-0deb-944940cd5511@net-b.de \
    --to=burnus@net-b.de \
    --cc=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=sandra@codesourcery.com \
    --cc=tobias@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).