public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108957] New: Fortran FE memleak with interfaces
@ 2023-02-27 22:15 anlauf at gcc dot gnu.org
  2023-03-06 18:46 ` [Bug fortran/108957] " mikael at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-02-27 22:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

            Bug ID: 108957
           Summary: Fortran FE memleak with interfaces
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

The frontend leaks memory for the following sample:

module m
  interface
     subroutine s ()
     end
  end interface
end

==7949== 3,176 (2,792 direct, 384 indirect) bytes in 1 blocks are definitely
lost in loss record 160 of 174
==7949==    at 0x4C39571: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7949==    by 0x2E5B904: xcalloc (xmalloc.c:164)
==7949==    by 0xC6C174: gfc_get_namespace(gfc_namespace*, int)
(symbol.cc:2875)
==7949==    by 0xC12CB0: parse_interface (parse.cc:3789)
==7949==    by 0xC12CB0: parse_spec(gfc_statement) (parse.cc:4150)
==7949==    by 0xC173D8: parse_module() (parse.cc:6531)
==7949==    by 0xC17851: gfc_parse_file() (parse.cc:6842)
==7949==    by 0xC76E02: gfc_be_parse_file() (f95-lang.cc:229)
==7949==    by 0x14F78AB: compile_file() (toplev.cc:444)
==7949==    by 0x14FA80B: do_compile(bool) (toplev.cc:2125)
==7949==    by 0x14FABD4: toplev::main(int, char**) (toplev.cc:2277)
==7949==    by 0x2D9DE05: main (main.cc:39)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
@ 2023-03-06 18:46 ` mikael at gcc dot gnu.org
  2023-03-06 18:55 ` mikael at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-06 18:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikael at gcc dot gnu.org

--- Comment #1 from Mikael Morin <mikael at gcc dot gnu.org> ---
This seems to do the trick for this testcase:

diff --git a/gcc/fortran/parse.cc b/gcc/fortran/parse.cc
index f1e55316e5b..f7670591fad 100644
--- a/gcc/fortran/parse.cc
+++ b/gcc/fortran/parse.cc
@@ -3864,9 +3864,6 @@ loop:
   accept_statement (st);
   prog_unit = gfc_new_block;
   prog_unit->formal_ns = gfc_current_ns;
-  if (prog_unit == prog_unit->formal_ns->proc_name
-      && prog_unit->ns != prog_unit->formal_ns)
-    prog_unit->refs++;

 decl:
   /* Read data declaration statements.  */


I can't fully test it right now.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
  2023-03-06 18:46 ` [Bug fortran/108957] " mikael at gcc dot gnu.org
@ 2023-03-06 18:55 ` mikael at gcc dot gnu.org
  2023-03-08 20:29 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-06 18:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

--- Comment #2 from Mikael Morin <mikael at gcc dot gnu.org> ---
Interestingly, the three lines removed in the previous comment come from a fix
for PR41093, whose title is "memory leaks with gfc_namespace".

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
  2023-03-06 18:46 ` [Bug fortran/108957] " mikael at gcc dot gnu.org
  2023-03-06 18:55 ` mikael at gcc dot gnu.org
@ 2023-03-08 20:29 ` anlauf at gcc dot gnu.org
  2023-09-07 20:20 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-03-08 20:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |memory-hog

--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to Mikael Morin from comment #1)
> This seems to do the trick for this testcase:
[...]
> I can't fully test it right now.

Regtests cleanly on x86_64-pc-linux-gnu here, and passes further tests.

And yes, the memleak is gone for the example.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-03-08 20:29 ` anlauf at gcc dot gnu.org
@ 2023-09-07 20:20 ` anlauf at gcc dot gnu.org
  2023-09-08  8:12 ` mikael at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-09-07 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

--- Comment #4 from anlauf at gcc dot gnu.org ---
Mikael,

are you still onto it?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-09-07 20:20 ` anlauf at gcc dot gnu.org
@ 2023-09-08  8:12 ` mikael at gcc dot gnu.org
  2023-09-15 11:43 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-09-08  8:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-09-08
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |mikael at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #5 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to anlauf from comment #4)
> Mikael,
> 
> are you still onto it?

Thanks for the reminder.
This PR had disappeared from my radar.
Taking it.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-09-08  8:12 ` mikael at gcc dot gnu.org
@ 2023-09-15 11:43 ` cvs-commit at gcc dot gnu.org
  2023-09-15 17:24 ` mikael at gcc dot gnu.org
  2023-09-15 17:25 ` mikael at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-09-15 11:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mikael Morin <mikael@gcc.gnu.org>:

https://gcc.gnu.org/g:e6dba708c8627080f4ca776590a191683b38336c

commit r14-4021-ge6dba708c8627080f4ca776590a191683b38336c
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Fri Sep 15 13:40:08 2023 +0200

    fortran: Remove reference count update [PR108957]

    Remove one reference count incrementation following the assignment of a
    symbol pointer to a local variable.  Most symbol pointers are "weak"
pointer
    and don't need any reference count update when they are assigned, and it is
    especially the case of local variables.

    This fixes a memory leak with the testcase from the PR (not included).

            PR fortran/108957

    gcc/fortran/ChangeLog:

            * gfortran.h (gfc_symbol): Add comment documenting reference
counting.
            * parse.cc (parse_interface): Remove reference count
incrementation.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-09-15 11:43 ` cvs-commit at gcc dot gnu.org
@ 2023-09-15 17:24 ` mikael at gcc dot gnu.org
  2023-09-15 17:25 ` mikael at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-09-15 17:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Mikael Morin <mikael at gcc dot gnu.org> ---
Fixed for gfortran 14, closing.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/108957] Fortran FE memleak with interfaces
  2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-09-15 17:24 ` mikael at gcc dot gnu.org
@ 2023-09-15 17:25 ` mikael at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-09-15 17:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108957

Mikael Morin <mikael at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-15 17:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27 22:15 [Bug fortran/108957] New: Fortran FE memleak with interfaces anlauf at gcc dot gnu.org
2023-03-06 18:46 ` [Bug fortran/108957] " mikael at gcc dot gnu.org
2023-03-06 18:55 ` mikael at gcc dot gnu.org
2023-03-08 20:29 ` anlauf at gcc dot gnu.org
2023-09-07 20:20 ` anlauf at gcc dot gnu.org
2023-09-08  8:12 ` mikael at gcc dot gnu.org
2023-09-15 11:43 ` cvs-commit at gcc dot gnu.org
2023-09-15 17:24 ` mikael at gcc dot gnu.org
2023-09-15 17:25 ` mikael at gcc dot gnu.org

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