From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 959703858404; Tue, 2 Apr 2024 13:11:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 959703858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712063485; bh=Oiwvy5Sf9BLtl8xYtcU+GCwSQNCX6I71G97BD4xB+O8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=g3d1QaqHZxs9kB6KlAF/E0ImIW0c6pcRprR+92ZiPdxfINURRK9qHKPMLDmRT7PWb kzqxm/m2t1uptxvyBkx2NQrTD8ghxpzxXww/OYvzxgww9NgZjH9szIsQ5dhCzqaWxw MBNLN3bYqDihk42geh/Io4wZxiM+NJCFfIF6MnU8= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 Date: Tue, 02 Apr 2024 13:11:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: ice-on-invalid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P4 X-Bugzilla-Assigned-To: mikael at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.4 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107426 --- Comment #13 from GCC Commits --- The releases/gcc-11 branch has been updated by Mikael Morin : https://gcc.gnu.org/g:3d05b9ac1c6ad950339f9487702c3165c189fe9e commit r11-11305-g3d05b9ac1c6ad950339f9487702c3165c189fe9e Author: Mikael Morin Date: Thu Mar 21 17:27:54 2024 +0100 fortran: Ignore use statements on error [PR107426] This fixes an access to freed memory on the testcase from the PR. The problem comes from an invalid subroutine statement in an interface, which is ignored and causes the following statements forming the proced= ure body to be rejected. One of them use-associates the intrinsic ISO_C_BINDING module, which imports new symbols in a namespace that is freed at the t= ime the statement is rejected. However, this creates dangling pointers as ISO_C_BINDING is special and its import creates a reference to the impo= rted C_PTR symbol in the return type of the global intrinsic symbol for C_LOC (see the function create_intrinsic_function). This change saves and restores the list of use statements, so that reje= cted use statements are removed before they have a chance to be applied to t= he current namespace and create dangling pointers. PR fortran/107426 gcc/fortran/ChangeLog: * gfortran.h (gfc_save_module_list, gfc_restore_old_module_list= ): New declarations. * module.c (old_module_list_tail): New global variable. (gfc_save_module_list, gfc_restore_old_module_list): New functi= ons. (gfc_use_modules): Set module_list and old_module_list_tail. * parse.c (next_statement): Save module_list before doing any w= ork. (reject_statement): Restore module_list to its saved value. gcc/testsuite/ChangeLog: * gfortran.dg/pr89943_3.f90: Update error pattern. * gfortran.dg/pr89943_4.f90: Likewise. * gfortran.dg/use_31.f90: New test. (cherry picked from commit a44d7e8a52007c2d45217709ca02947c6600de87)=