public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/110987] New: Segmentation fault after finalization of a temporary variable
@ 2023-08-11  9:11 chilikin.k at gmail dot com
  2023-08-11  9:12 ` [Bug fortran/110987] " chilikin.k at gmail dot com
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: chilikin.k at gmail dot com @ 2023-08-11  9:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110987
           Summary: Segmentation fault after finalization of a temporary
                    variable
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chilikin.k at gmail dot com
  Target Milestone: ---

Created attachment 55720
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55720&action=edit
Test case

The attached test program works fine with gfortran 12.2.0 and crashes with
a segmentation fault when compiled with gfortran 13.2.0. The compilation
command is

gfortran -g -o test test.f90

The segmentation fault happens when the function T1_GET_NEXT() tries to access
SELF%NEXT(1)%T1, which is deallocated and overwritten:

$ valgrind ./test

==1651009== Invalid read of size 8
==1651009==    at 0x40251D: __test_module_MOD_t1_get_next (in test)
==1651009==    by 0x403678: MAIN__ (in test)
==1651009==    by 0x4036D0: main (in test)
==1651009==  Address 0x4e92d48 is 8 bytes inside a block of size 16 free'd
==1651009==    at 0x48399AB: free (vg_replace_malloc.c:538)
==1651009==    by 0x402876: __test_module_MOD_t1_destructor (in test)
==1651009==    by 0x401812: __test_module_MOD___final_test_module_T1 (in test)
==1651009==    by 0x4035CF: MAIN__ (in test)
==1651009==    by 0x4036D0: main (in test)
==1651009==  Block was alloc'd at
==1651009==    at 0x483877F: malloc (vg_replace_malloc.c:307)
==1651009==    by 0x4026AF: __test_module_MOD_t1_set_n_next (in test)
==1651009==    by 0x402466: __test_module_MOD_t2_constructor (in test)
==1651009==    by 0x402E93: MAIN__ (in test)
==1651009==    by 0x4036D0: main (in test)

The corresponding part of the output of

$ objdump -S ./test | less

is attached. The final-subroutine call which incorrectly deallocates memory
happens at 4035cd, between the calls of __test_module_MOD_t3_constructor and
__test_module_MOD_t1_set_n_next. Thus, the finalization seems to happen for
the temporary variable allocated as the result of T3() call, which is assigned
then to X3, and the memory corresponding to

    CLASS(T1_POINTER), ALLOCATABLE :: NEXT(:)

is probably the same for that temporary variable and X3 (in contradiction with
10.2.1.3.13 item (2) of Fortran 2018?).

May be related to the fix of bug 80524.

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

end of thread, other threads:[~2024-05-06  9:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11  9:11 [Bug fortran/110987] New: Segmentation fault after finalization of a temporary variable chilikin.k at gmail dot com
2023-08-11  9:12 ` [Bug fortran/110987] " chilikin.k at gmail dot com
2023-08-31 18:51 ` chilikin.k at gmail dot com
2023-12-09 13:27 ` chilikin.k at gmail dot com
2024-02-04 20:51 ` anlauf at gcc dot gnu.org
2024-02-05 15:37 ` jhaiduce at gmail dot com
2024-02-05 15:54 ` jhaiduce at gmail dot com
2024-02-05 17:27 ` [Bug fortran/110987] [13/14 Regression] " anlauf at gcc dot gnu.org
2024-02-05 17:34 ` anlauf at gcc dot gnu.org
2024-03-22 13:40 ` law at gcc dot gnu.org
2024-03-28 15:59 ` pault at gcc dot gnu.org
2024-03-29  7:23 ` cvs-commit at gcc dot gnu.org
2024-04-23  9:47 ` [Bug fortran/110987] [13 " pault at gcc dot gnu.org
2024-05-06  9:47 ` cvs-commit at gcc dot gnu.org
2024-05-06  9:50 ` pault 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).