public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "chilikin.k at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/110987] New: Segmentation fault after finalization of a temporary variable Date: Fri, 11 Aug 2023 09:11:20 +0000 [thread overview] Message-ID: <bug-110987-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2023-08-11 9:11 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-08-11 9:11 chilikin.k at gmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-110987-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).