public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-9244] fortran: Reuse associated_dummy memory if previously allocated [PR108923]
@ 2023-03-12 10:48 Mikael Morin
  0 siblings, 0 replies; only message in thread
From: Mikael Morin @ 2023-03-12 10:48 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7b0c9631ccb492c4457a91dbb91e7a5bcd0bc2a6

commit r12-9244-g7b0c9631ccb492c4457a91dbb91e7a5bcd0bc2a6
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Sat Feb 25 21:37:46 2023 +0100

    fortran: Reuse associated_dummy memory if previously allocated [PR108923]
    
    This avoids making the associted_dummy field point to a new memory chunk
    if it's already pointing somewhere, in which case doing so would leak the
    previously allocated chunk.
    
            PR fortran/108923
    
    gcc/fortran/ChangeLog:
    
            * intrinsic.cc (get_intrinsic_dummy_arg,
            set_intrinsic_dummy_arg): Rename the former to the latter.
            Remove the return value, add a reference to the lhs as argument,
            and do the pointer assignment inside the function.  Don't do
            it if the pointer is already non-NULL.
            (sort_actual): Update caller.
    
    (cherry picked from commit 5c638095e7e0fa4de4e4f7326384a86830b25732)

Diff:
---
 gcc/fortran/intrinsic.cc | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/fortran/intrinsic.cc b/gcc/fortran/intrinsic.cc
index e89131f5a71..ff5d728bb06 100644
--- a/gcc/fortran/intrinsic.cc
+++ b/gcc/fortran/intrinsic.cc
@@ -4259,15 +4259,15 @@ remove_nullargs (gfc_actual_arglist **ap)
 }
 
 
-static gfc_dummy_arg *
-get_intrinsic_dummy_arg (gfc_intrinsic_arg *intrinsic)
+static void
+set_intrinsic_dummy_arg (gfc_dummy_arg *&dummy_arg,
+			 gfc_intrinsic_arg *intrinsic)
 {
-  gfc_dummy_arg * const dummy_arg = gfc_get_dummy_arg ();
+  if (dummy_arg == NULL)
+    dummy_arg = gfc_get_dummy_arg ();
 
   dummy_arg->intrinsicness = GFC_INTRINSIC_DUMMY_ARG;
   dummy_arg->u.intrinsic = intrinsic;
-
-  return dummy_arg;
 }
 
 
@@ -4430,7 +4430,7 @@ do_sort:
       if (a == NULL)
 	a = gfc_get_actual_arglist ();
 
-      a->associated_dummy = get_intrinsic_dummy_arg (f);
+      set_intrinsic_dummy_arg (a->associated_dummy, f);
 
       if (actual == NULL)
 	*ap = a;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-12 10:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-12 10:48 [gcc r12-9244] fortran: Reuse associated_dummy memory if previously allocated [PR108923] Mikael Morin

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).