]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix proc pointer as elemental arg handling
authorTobias Burnus <tobias@codesourcery.com>
Thu, 12 May 2022 08:39:58 +0000 (10:39 +0200)
committerKwok Cheung Yeung <kcy@codesourcery.com>
Tue, 28 Jun 2022 20:55:25 +0000 (13:55 -0700)
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.

gcc/fortran/ChangeLog.omp
gcc/fortran/trans-array.cc
gcc/testsuite/ChangeLog.omp
gcc/testsuite/gfortran.dg/finalize_38.f90

index 0a735989f0cba5e4282ee3492f5d482f44b66bdf..9d5d25477670f3cf735b08439a97fdebee863675 100644 (file)
@@ -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
index 7ebe0c9196cb67d913efc3e00121c773c2f19d53..43b65c5e62965407465a641f4eb2aca24a865522 100644 (file)
@@ -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;
index bc57cf741f5118b2b94717e4ed95463cc6ee5606..c3712b40d0127651741c2fabb239fe5b4351c076 100644 (file)
@@ -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
index 442e175331109f205dff8d3c5993ac5ed3527ea3..99c288784d64d2c0e029d224bd57624054cddc63 100644 (file)
@@ -1,4 +1,5 @@
 ! { dg-do compile }
+! { dg-additional-options "-Ofast" }
 !
 ! Check finalization
 !