public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tobias Burnus <tobias@codesourcery.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>, Jakub Jelinek <jakub@redhat.com>
Subject: [OG11-committed] Fortran: Fix proc pointer as elemental arg handling (was: Fortran: Fix finalization resolution with deep copy (was: [Patch][Stage 1] Fortran/OpenMP: Support mapping of DT with allocatable components))
Date: Thu, 12 May 2022 11:23:37 +0200	[thread overview]
Message-ID: <1295021c-1f69-01b8-9d08-987c731c5711@codesourcery.com> (raw)
In-Reply-To: <204e23b8-9d98-8ebf-d672-444ad371ed47@codesourcery.com>

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

Found another issue related to polymorphic deep copy (see description in the commit log).

I plan to start submitting the deep-mapping patches in separate pieces to mainline later during Stage 1.

Tobias
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

[-- Attachment #2: committed.diff --]
[-- Type: text/x-patch, Size: 2392 bytes --]

commit ee954d940c41614c75be11b9d1de9079c37044d7
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Thu May 12 10:39:58 2022 +0200

    Fortran: Fix proc pointer as elemental arg handling
    
    The vtab's _callback function calls the elemental 'cb'
      cb (var(:)%comp, comp_types_vtable._callback);
    which gets called in a scalarization loop as 'var' might be a
    nonscalar. Without the patch, that got translated as:
      D.1234 = &comp_types_vtable._callback
      ...
       cb (&(*D.4060)[S.3 + D.4071], &D.1234);
    where 'D.1234' is function_type. With the patch, it remains a pointer;
    i.e. D.1234 = comp... and 'cb (..., D.1234)', avoiding ME ICE.
    
    Note: Fortran (F2018, C15100) requires that dummy arguments are
    dummy data objects, which rules out dummy procs/proc-pointer dummies,
    which is enforced in resolve_fl_procedure.
    Thus, this change only affects the internally generated code.
    
    gcc/fortran/ChangeLog:
    
            * trans-array.c (gfc_scalar_elemental_arg_saved_as_reference):
            Return true for attr.proc_pointer expressions.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/finalize_38.f90: Compile with -Ofast.
---
 gcc/fortran/trans-array.c                 | 6 ++++++
 gcc/testsuite/gfortran.dg/finalize_38.f90 | 1 +
 2 files changed, 7 insertions(+)

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 0d637162509..8e5277594ab 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3025,6 +3025,12 @@ gfc_scalar_elemental_arg_saved_as_reference (gfc_ss_info * ss_info)
       && gfc_expr_is_variable (ss_info->expr))
     return true;
 
+  /* Proc pointers: avoid creating a non-pointer function temporary;
+     should only get used internally due to constraints. */
+  if (!ss_info->data.scalar.needs_temporary &&
+      gfc_expr_attr (ss_info->expr).proc_pointer)
+    return true;
+
   /* Otherwise the expression is evaluated to a temporary variable before the
      scalarization loop.  */
   return false;
diff --git a/gcc/testsuite/gfortran.dg/finalize_38.f90 b/gcc/testsuite/gfortran.dg/finalize_38.f90
index 442e1753311..99c288784d6 100644
--- a/gcc/testsuite/gfortran.dg/finalize_38.f90
+++ b/gcc/testsuite/gfortran.dg/finalize_38.f90
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-additional-options "-Ofast" }
 !
 ! Check finalization
 !

      reply	other threads:[~2022-05-12  9:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 15:34 [Patch][Stage 1] Fortran/OpenMP: Support mapping of DT with allocatable components Tobias Burnus
2022-03-02 22:20 ` Tobias Burnus
2022-04-25 13:47   ` [OG11-committed][stage1-patch] Fortran: Fix finalization resolution with deep copy (was: [Patch][Stage 1] Fortran/OpenMP: Support mapping of DT with allocatable components) Tobias Burnus
2022-04-27 17:54     ` Tobias Burnus
2022-05-12  9:23       ` Tobias Burnus [this message]

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=1295021c-1f69-01b8-9d08-987c731c5711@codesourcery.com \
    --to=tobias@codesourcery.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.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).