public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Kwok Yeung <kcy@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc/devel/omp/gcc-12] Fortran: Fix proc pointer as elemental arg handling
Date: Wed, 29 Jun 2022 14:46:41 +0000 (GMT)	[thread overview]
Message-ID: <20220629144641.82EC13851A87@sourceware.org> (raw)

https://gcc.gnu.org/g:213577701d178daf01480859a27303b680122b91

commit 213577701d178daf01480859a27303b680122b91
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.cc (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.

Diff:
---
 gcc/fortran/ChangeLog.omp                 | 5 +++++
 gcc/fortran/trans-array.cc                | 6 ++++++
 gcc/testsuite/ChangeLog.omp               | 4 ++++
 gcc/testsuite/gfortran.dg/finalize_38.f90 | 1 +
 4 files changed, 16 insertions(+)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index 0a735989f0c..9d5d2547767 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,8 @@
+2022-05-12  Tobias Burnus  <tobias@codesourcery.com>
+
+	* trans-array.cc (gfc_scalar_elemental_arg_saved_as_reference):
+	Return true for attr.proc_pointer expressions.
+
 2022-04-27  Tobias Burnus <tobias@codesourcery.com>
 
 	* resolve.cc (gfc_resolve_finalizers): Remove
diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 7ebe0c9196c..43b65c5e629 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -3026,6 +3026,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/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index bc57cf741f5..c3712b40d01 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,7 @@
+2022-05-12  Tobias Burnus  <tobias@codesourcery.com>
+
+	* gfortran.dg/finalize_38.f90: Compile with -Ofast.
+
 2022-04-27  Tobias Burnus <tobias@codesourcery.com>
 
 	* gfortran.dg/abstract_type_6.f03: Remove dg-error as
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-06-29 14:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220629144641.82EC13851A87@sourceware.org \
    --to=kcy@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).