public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
@ 2022-10-26 18:40 gscfq@t-online.de
  2022-10-26 19:42 ` [Bug fortran/107426] " anlauf at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: gscfq@t-online.de @ 2022-10-26 18:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107426
           Summary: [12/13 Regression] ICE in gfc_compare_derived_types,
                    at fortran/interface.cc:636
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Started between 20210905 and 20210919 :


$ cat z1.f90
module m
contains
   subroutine p() bind(c)
      use, intrinsic :: iso_c_binding
      integer, target :: a = 1
      type(c_ptr) :: z
      interface
         subroutine s(x) bind(cc)   !!
            use, intrinsic :: iso_c_binding
            integer(c_int), value :: x
         end
      end interface
      z = c_loc(a)
      call s(z)
   end
end


$ gfortran-13-20221023 -c z0.f90   # corrected cc -> c at marker !!
z0.f90:14:15:

   14 |       call s(z)
      |               1
Error: Type mismatch in argument 'x' at (1); passed TYPE(c_ptr) to INTEGER(4)


$ gfortran-13-20221023 -c z1.f90
z1.f90:8:32:

    8 |          subroutine s(x) bind(cc)   !!
      |                                1
Error: Missing closing paren for binding label at (1)
z1.f90:9:43:

    9 |             use, intrinsic :: iso_c_binding
      |                                           1
Error: Unexpected USE statement in INTERFACE block at (1)
z1.f90:10:38:

   10 |             integer(c_int), value :: x
      |                                      1
Error: Unexpected data declaration statement in INTERFACE block at (1)
z1.f90:11:12:

   11 |          end
      |            1
Error: END INTERFACE statement expected at (1)
f951: internal compiler error: Segmentation fault
0xf43b3f crash_signal
        ../../gcc/toplev.cc:314
0x806bce gfc_compare_derived_types(gfc_symbol*, gfc_symbol*)
        ../../gcc/fortran/interface.cc:636
0x800803 gfc_check_assign(gfc_expr*, gfc_expr*, int, bool)
        ../../gcc/fortran/expr.cc:3830
0x86d655 resolve_ordinary_assign
        ../../gcc/fortran/resolve.cc:11222
0x87628b gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.cc:12123
0x878307 resolve_codes
        ../../gcc/fortran/resolve.cc:17624
0x87823e resolve_codes
        ../../gcc/fortran/resolve.cc:17607
0x8783ce gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.cc:17659
0x85ff92 gfc_parse_file()
        ../../gcc/fortran/parse.cc:6837
0x8aec0f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.cc:229

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
@ 2022-10-26 19:42 ` anlauf at gcc dot gnu.org
  2022-10-27  0:22 ` kargl at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-10-26 19:42 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-10-26

--- Comment #1 from anlauf at gcc dot gnu.org ---
Interesting.

Adding an ,only to any of the use, intrinsic :: iso_c_binding statements
avoids the ICE.

However, I get an ICE down to gcc-7, so I am not sure that the reported
regression is accurate.

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
  2022-10-26 19:42 ` [Bug fortran/107426] " anlauf at gcc dot gnu.org
@ 2022-10-27  0:22 ` kargl at gcc dot gnu.org
  2022-10-28 11:35 ` rguenth at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-10-27  0:22 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

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

--- Comment #2 from kargl at gcc dot gnu.org ---
I don't see this on x86_64-*-freebsd, but I also build with
--enable-checking=yes which may or may not mask issues.  I'll note that running
valgrind on `f951 a.f90` yields a long listing which starts with

Error: END INTERFACE statement expected at (1)
==81746== Invalid read of size 8
==81746==    at 0x899905: gfc_find_typebound_intrinsic_op(gfc_symbol*, bool*,
gfc_intrinsic_op, bool, locus*) (class.cc:3023)
==81746==    by 0x8CDED8: matching_typebound_op(gfc_expr**,
gfc_actual_arglist*, gfc_intrinsic_op, char const*, char const**)
(interface.cc:4415)
==81746==    by 0x8CE72C: gfc_extend_assign(gfc_code*, gfc_namespace*)
(interfac

probably not a good thing.

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
  2022-10-26 19:42 ` [Bug fortran/107426] " anlauf at gcc dot gnu.org
  2022-10-27  0:22 ` kargl at gcc dot gnu.org
@ 2022-10-28 11:35 ` rguenth at gcc dot gnu.org
  2023-03-12 12:31 ` mikael at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-10-28 11:35 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.3
           Priority|P3                          |P4

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2022-10-28 11:35 ` rguenth at gcc dot gnu.org
@ 2023-03-12 12:31 ` mikael at gcc dot gnu.org
  2023-03-12 16:45 ` mikael at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-12 12:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #3 from Mikael Morin <mikael at gcc dot gnu.org> ---
Created attachment 54641
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54641&action=edit
Draft patch

I couldn't track the exact path of the memory error reported by valgrind, but
the attached patch "fixes" (well, it makes it latent I guess) the problem by
removing from the use statement list the statements that are rejected.

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2023-03-12 12:31 ` mikael at gcc dot gnu.org
@ 2023-03-12 16:45 ` mikael at gcc dot gnu.org
  2023-03-12 16:47 ` mikael at gcc dot gnu.org
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-12 16:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Mikael Morin <mikael at gcc dot gnu.org> ---
Created attachment 54642
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54642&action=edit
Dra

(In reply to Mikael Morin from comment #3)
> Created attachment 54641 [details]
> Draft patch
> 
> I couldn't track the exact path of the memory error reported by valgrind,
> but the attached patch "fixes" (well, it makes it latent I guess) the
> problem by removing from the use statement list the statements that are
> rejected.

There is a bug in it: new use statements are at the end of the linked list, not
at the beginning.

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2023-03-12 16:45 ` mikael at gcc dot gnu.org
@ 2023-03-12 16:47 ` mikael at gcc dot gnu.org
  2023-03-12 17:31 ` mikael at gcc dot gnu.org
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-12 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54641|0                           |1
        is obsolete|                            |
  Attachment #54642|0                           |1
        is obsolete|                            |

--- Comment #5 from Mikael Morin <mikael at gcc dot gnu.org> ---
Created attachment 54643
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54643&action=edit
Corrected draft patch

(In reply to Mikael Morin from comment #4)
> Created attachment 54642 [details]
> Dra
> 
I was meaning: Draft patch, corrected.

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

* [Bug fortran/107426] [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2023-03-12 16:47 ` mikael at gcc dot gnu.org
@ 2023-03-12 17:31 ` mikael at gcc dot gnu.org
  2023-05-08 12:25 ` [Bug fortran/107426] [12/13/14 " rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-03-12 17:31 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54643|0                           |1
        is obsolete|                            |

--- Comment #6 from Mikael Morin <mikael at gcc dot gnu.org> ---
Created attachment 54644
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54644&action=edit
Corrected patch

The previous patch was broken in multiple ways.  This one works.

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (6 preceding siblings ...)
  2023-03-12 17:31 ` mikael at gcc dot gnu.org
@ 2023-05-08 12:25 ` rguenth at gcc dot gnu.org
  2024-03-22 13:33 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (7 preceding siblings ...)
  2023-05-08 12:25 ` [Bug fortran/107426] [12/13/14 " rguenth at gcc dot gnu.org
@ 2024-03-22 13:33 ` cvs-commit at gcc dot gnu.org
  2024-03-30  9:13 ` pault at gcc dot gnu.org
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-22 13:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from GCC 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:a44d7e8a52007c2d45217709ca02947c6600de87

commit r14-9619-ga44d7e8a52007c2d45217709ca02947c6600de87
Author: Mikael Morin <mikael@gcc.gnu.org>
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 procedure
    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 time
    the statement is rejected.  However, this creates dangling pointers as
    ISO_C_BINDING is special and its import creates a reference to the imported
    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 rejected
    use statements are removed before they have a chance to be applied to the
    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.cc (old_module_list_tail): New global variable.
            (gfc_save_module_list, gfc_restore_old_module_list): New functions.
            (gfc_use_modules): Set module_list and old_module_list_tail.
            * parse.cc (next_statement): Save module_list before doing any
work.
            (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.

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (8 preceding siblings ...)
  2024-03-22 13:33 ` cvs-commit at gcc dot gnu.org
@ 2024-03-30  9:13 ` pault at gcc dot gnu.org
  2024-03-30 10:28 ` mikael at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pault at gcc dot gnu.org @ 2024-03-30  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

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

--- Comment #9 from Paul Thomas <pault at gcc dot gnu.org> ---
Hi Mikael,

I have assigned the PR to you since you have fixed it on mainline. I presume
that you will backport?

Regards

Paul

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (9 preceding siblings ...)
  2024-03-30  9:13 ` pault at gcc dot gnu.org
@ 2024-03-30 10:28 ` mikael at gcc dot gnu.org
  2024-03-31 14:25 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2024-03-30 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #10 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Paul Thomas from comment #9)
> Hi Mikael,
> 
> I have assigned the PR to you since you have fixed it on mainline. I presume
> that you will backport?
> 
Yes.  I was initially targetting master only, but then I figured this was a
regression, so backporting was in order.

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (10 preceding siblings ...)
  2024-03-30 10:28 ` mikael at gcc dot gnu.org
@ 2024-03-31 14:25 ` cvs-commit at gcc dot gnu.org
  2024-04-02 13:08 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-31 14:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Mikael Morin
<mikael@gcc.gnu.org>:

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

commit r13-8543-gfc5c603da3c9b186308fb3afef7bcf3f3bf695e8
Author: Mikael Morin <mikael@gcc.gnu.org>
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 procedure
    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 time
    the statement is rejected.  However, this creates dangling pointers as
    ISO_C_BINDING is special and its import creates a reference to the imported
    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 rejected
    use statements are removed before they have a chance to be applied to the
    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.cc (old_module_list_tail): New global variable.
            (gfc_save_module_list, gfc_restore_old_module_list): New functions.
            (gfc_use_modules): Set module_list and old_module_list_tail.
            * parse.cc (next_statement): Save module_list before doing any
work.
            (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)

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (11 preceding siblings ...)
  2024-03-31 14:25 ` cvs-commit at gcc dot gnu.org
@ 2024-04-02 13:08 ` cvs-commit at gcc dot gnu.org
  2024-04-02 13:11 ` cvs-commit at gcc dot gnu.org
  2024-04-02 13:13 ` mikael at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 13:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Mikael Morin
<mikael@gcc.gnu.org>:

https://gcc.gnu.org/g:38dd703d368c9e60159e6f19cfc8303ad639b557

commit r12-10305-g38dd703d368c9e60159e6f19cfc8303ad639b557
Author: Mikael Morin <mikael@gcc.gnu.org>
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 procedure
    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 time
    the statement is rejected.  However, this creates dangling pointers as
    ISO_C_BINDING is special and its import creates a reference to the imported
    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 rejected
    use statements are removed before they have a chance to be applied to the
    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.cc (old_module_list_tail): New global variable.
            (gfc_save_module_list, gfc_restore_old_module_list): New functions.
            (gfc_use_modules): Set module_list and old_module_list_tail.
            * parse.cc (next_statement): Save module_list before doing any
work.
            (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)

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (12 preceding siblings ...)
  2024-04-02 13:08 ` cvs-commit at gcc dot gnu.org
@ 2024-04-02 13:11 ` cvs-commit at gcc dot gnu.org
  2024-04-02 13:13 ` mikael at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-02 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Mikael Morin
<mikael@gcc.gnu.org>:

https://gcc.gnu.org/g:3d05b9ac1c6ad950339f9487702c3165c189fe9e

commit r11-11305-g3d05b9ac1c6ad950339f9487702c3165c189fe9e
Author: Mikael Morin <mikael@gcc.gnu.org>
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 procedure
    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 time
    the statement is rejected.  However, this creates dangling pointers as
    ISO_C_BINDING is special and its import creates a reference to the imported
    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 rejected
    use statements are removed before they have a chance to be applied to the
    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 functions.
            (gfc_use_modules): Set module_list and old_module_list_tail.
            * parse.c (next_statement): Save module_list before doing any work.
            (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)

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

* [Bug fortran/107426] [12/13/14 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636
  2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
                   ` (13 preceding siblings ...)
  2024-04-02 13:11 ` cvs-commit at gcc dot gnu.org
@ 2024-04-02 13:13 ` mikael at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: mikael at gcc dot gnu.org @ 2024-04-02 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #14 from Mikael Morin <mikael at gcc dot gnu.org> ---
Fixed for gfortran versions 14.1, 13.3, 12.4 and 11.5.
Closing.

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

end of thread, other threads:[~2024-04-02 13:13 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 18:40 [Bug fortran/107426] New: [12/13 Regression] ICE in gfc_compare_derived_types, at fortran/interface.cc:636 gscfq@t-online.de
2022-10-26 19:42 ` [Bug fortran/107426] " anlauf at gcc dot gnu.org
2022-10-27  0:22 ` kargl at gcc dot gnu.org
2022-10-28 11:35 ` rguenth at gcc dot gnu.org
2023-03-12 12:31 ` mikael at gcc dot gnu.org
2023-03-12 16:45 ` mikael at gcc dot gnu.org
2023-03-12 16:47 ` mikael at gcc dot gnu.org
2023-03-12 17:31 ` mikael at gcc dot gnu.org
2023-05-08 12:25 ` [Bug fortran/107426] [12/13/14 " rguenth at gcc dot gnu.org
2024-03-22 13:33 ` cvs-commit at gcc dot gnu.org
2024-03-30  9:13 ` pault at gcc dot gnu.org
2024-03-30 10:28 ` mikael at gcc dot gnu.org
2024-03-31 14:25 ` cvs-commit at gcc dot gnu.org
2024-04-02 13:08 ` cvs-commit at gcc dot gnu.org
2024-04-02 13:11 ` cvs-commit at gcc dot gnu.org
2024-04-02 13:13 ` 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).