[fortran] PR112459 - gfortran -w option causes derived-type finalization at creation time

Message ID CAGkQGiJ9KDmOZqgHH9eM1ytPGTtjG_-F+ekP0f5w46OjcEZNkw@mail.gmail.com
State Accepted
Headers
Series [fortran] PR112459 - gfortran -w option causes derived-type finalization at creation time |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Paul Richard Thomas Nov. 11, 2023, 10:15 a.m. UTC
  Hi All,

Evidently -w causes gfc_option.allow_std to be set to default, which allows
anything and everything to happen, including these f2003/8 finalizations.
The fix is trivial.

Regtests fine - OK for mainline and -13 branch?

Paul

Fortran: Prevent unwanted finalization with -w option [PR112459]

2023-11-11  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR fortran/112459
* trans-array.cc (gfc_trans_array_constructor_value): Replace
gfc_notification_std with explicit logical expression that
selects F2003/2008 and excludes -std=default/gnu.
*trans-array.cc (gfc_conv_expr): Ditto.

gcc/testsuite/
PR fortran/112459
* gfortran.dg/pr112459.f90: New test.
  

Comments

Harald Anlauf Nov. 11, 2023, 7:10 p.m. UTC | #1
Hi Paul,

this is OK.

Thanks for the patch!

Harald

Am 11.11.23 um 11:15 schrieb Paul Richard Thomas:
> Hi All,
> 
> Evidently -w causes gfc_option.allow_std to be set to default, which allows
> anything and everything to happen, including these f2003/8 finalizations.
> The fix is trivial.
> 
> Regtests fine - OK for mainline and -13 branch?
> 
> Paul
> 
> Fortran: Prevent unwanted finalization with -w option [PR112459]
> 
> 2023-11-11  Paul Thomas  <pault@gcc.gnu.org>
> 
> gcc/fortran
> PR fortran/112459
> * trans-array.cc (gfc_trans_array_constructor_value): Replace
> gfc_notification_std with explicit logical expression that
> selects F2003/2008 and excludes -std=default/gnu.
> *trans-array.cc (gfc_conv_expr): Ditto.
> 
> gcc/testsuite/
> PR fortran/112459
> * gfortran.dg/pr112459.f90: New test.
>
  

Patch

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index bbb81f40aa9..ef54a20dafd 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -2311,7 +2311,9 @@  gfc_trans_array_constructor_value (stmtblock_t * pblock,
      Corrigenda 1 TO 4 for fortran 2008 (f08/0011).
 
      Transmit finalization of this constructor through 'finalblock'. */
-  if (!gfc_notification_std (GFC_STD_F2018_DEL) && finalblock != NULL
+  if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003))
+      && !(gfc_option.allow_std & GFC_STD_GNU)
+      && finalblock != NULL
       && gfc_may_be_finalized (ts)
       && ctr > 0 && desc != NULL_TREE
       && GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (desc)))
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 1b8be081a17..a69d7c7114d 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -9698,7 +9698,9 @@  gfc_conv_expr (gfc_se * se, gfc_expr * expr)
 	 executable construct containing the reference. This, in fact,
 	 was later deleted by the Combined Techical Corrigenda 1 TO 4 for
 	 fortran 2008 (f08/0011).  */
-      if (!gfc_notification_std (GFC_STD_F2018_DEL) && expr->must_finalize
+      if ((gfc_option.allow_std & (GFC_STD_F2008 | GFC_STD_F2003))
+	  && !(gfc_option.allow_std & GFC_STD_GNU)
+	  && expr->must_finalize
 	  && gfc_may_be_finalized (expr->ts))
 	{
 	  gfc_warning (0, "The structure constructor at %C has been"