public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
@ 2011-04-26 18:46 burnus at gcc dot gnu.org
  2013-06-16 13:13 ` [Bug fortran/48776] " dominiq at lps dot ens.fr
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-04-26 18:46 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48776

           Summary: ICE(segfault) after -std=f95 diagnostic error
                    involving PROCEDURE
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: error-recovery, ice-on-invalid-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org


Follow up to bug 48279 comment 7 and 48279 comment 11.

The following program segfaults with -std=f95 after printing the diagnostic:

    procedure get1
                  1
Error: Fortran 2003: PROCEDURE statement at (1)
f951: internal compiler error: Segmentation fault


Valgrind shows tons of errors, starting with:

==22545== Invalid read of size 8
==22545==    at 0x52FD8C: resolve_symbol (resolve.c:10004)
==22545==    by 0x54BA76: traverse_ns (symbol.c:3379)
==22545==    by 0x53919B: resolve_types (resolve.c:13261)
==22545==    by 0x52E3D3: gfc_resolve (resolve.c:13357)

The testcase:

  interface get
    procedure get1
  end interface

  integer :: h
  call set1 (get (h))
contains
  subroutine set1 (a)
    integer, intent(in) :: a
  end subroutine

  integer function get1 (s)
    integer :: s
  end function
end


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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
@ 2013-06-16 13:13 ` dominiq at lps dot ens.fr
  2023-08-26 18:29 ` mikael at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2013-06-16 13:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48776

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-06-16
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Still present at revision 200128.


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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
  2013-06-16 13:13 ` [Bug fortran/48776] " dominiq at lps dot ens.fr
@ 2023-08-26 18:29 ` mikael at gcc dot gnu.org
  2023-08-26 18:30 ` mikael at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-08-26 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Mikael Morin <mikael at gcc dot gnu.org> ---
Can't reproduce with a recent master (14.0.0 20230814).

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
  2013-06-16 13:13 ` [Bug fortran/48776] " dominiq at lps dot ens.fr
  2023-08-26 18:29 ` mikael at gcc dot gnu.org
@ 2023-08-26 18:30 ` mikael at gcc dot gnu.org
  2023-08-26 19:47 ` mikael at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-08-26 18:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Mikael Morin <mikael at gcc dot gnu.org> ---
(In reply to Mikael Morin from comment #6)
> Can't reproduce with a recent master (14.0.0 20230814).

Sorry, missed the -std=f95 flag.
Confirmed on recent master.

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-08-26 18:30 ` mikael at gcc dot gnu.org
@ 2023-08-26 19:47 ` mikael at gcc dot gnu.org
  2023-08-30 12:20 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-08-26 19:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |mikael at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

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

This seems to work on comment #0.
Not tested otherwise.

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-08-26 19:47 ` mikael at gcc dot gnu.org
@ 2023-08-30 12:20 ` cvs-commit at gcc dot gnu.org
  2023-08-30 19:38 ` mikael at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-30 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 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:d58150452976c4ca65ddc811fac78ef956fa96b0

commit r14-3572-gd58150452976c4ca65ddc811fac78ef956fa96b0
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Wed Aug 30 14:18:56 2023 +0200

    fortran: Restore interface to its previous state on error [PR48776]

    Keep memory of the content of the current interface body being parsed
    and restore it to its previous state if it has been modified at the time
    a parse attempt fails.

    This fixes memory errors and random segmentation faults caused by
    dangling symbol pointers kept in interfaces' linked lists of symbols.
    If a parsing attempt fails and symbols are freed, they should also be
    removed from the current interface linked list.

    As the list of symbol is a linked list, and parsing only adds new
    symbols to the head of the list, all that is needed to track the
    previous content of the list is a pointer to its previous head.
    This adds such a pointer, and the restoration of the list of symbols
    to that pointer on error.

            PR fortran/48776

    gcc/fortran/ChangeLog:

            * gfortran.h (gfc_drop_interface_elements_before): New prototype.
            (gfc_current_interface_head): Return a reference to the pointer.
            * interface.cc (gfc_current_interface_head): Ditto.
            (free_interface_elements_until): New function, generalizing
            gfc_free_interface.
            (gfc_free_interface): Use free_interface_elements_until.
            (gfc_drop_interface_elements_before): New function.
            * parse.cc
            (current_interface_ptr, previous_interface_head): New static
variables.
            (current_interface_valid_p, get_current_interface_ptr): New
functions.
            (decode_statement): Initialize previous_interface_head.
            (reject_statement): Restore current interface pointer to point to
            previous_interface_head.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/interface_procedure_1.f90: New test.

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-08-30 12:20 ` cvs-commit at gcc dot gnu.org
@ 2023-08-30 19:38 ` mikael at gcc dot gnu.org
  2023-08-30 19:39 ` mikael at gcc dot gnu.org
  2024-01-20 15:50 ` cvs-commit at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-08-30 19:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gscfq@t-online.de

--- Comment #10 from Mikael Morin <mikael at gcc dot gnu.org> ---
*** Bug 107923 has been marked as a duplicate of this bug. ***

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-08-30 19:38 ` mikael at gcc dot gnu.org
@ 2023-08-30 19:39 ` mikael at gcc dot gnu.org
  2024-01-20 15:50 ` cvs-commit at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: mikael at gcc dot gnu.org @ 2023-08-30 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #11 from Mikael Morin <mikael at gcc dot gnu.org> ---
Fixed for gcc 14.
Closing.

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

* [Bug fortran/48776] ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE
  2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-08-30 19:39 ` mikael at gcc dot gnu.org
@ 2024-01-20 15:50 ` cvs-commit at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-20 15:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 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:6930e1f1055c39bea170c25f694f7301989e5d1d

commit r14-8305-g6930e1f1055c39bea170c25f694f7301989e5d1d
Author: Mikael Morin <mikael@gcc.gnu.org>
Date:   Fri Jan 19 18:47:36 2024 +0100

    fortran: Restore current interface info on error [PR111291]

    This change is a followup to the fix for PR48776 (namely
    r14-3572-gd58150452976c4ca65ddc811fac78ef956fa96b0 AKA
    fortran: Restore interface to its previous state on error [PR48776]),
    which cleaned up new changes from interfaces upon error.

    Unfortunately, there is one case in that fix that is mishandled, visible
    on unexpected_interface.f90 with valgrind or an asan-instrumented gfortran.
    when an interface statement is found while parsing an interface body (which
    is invalid), the current interface is replaced by the one from the new
    statement, and as parsing continues, new procedures are added
    to the new interface, which has been rejected and freed, instead of the
    original one.

    This change restores the current interface pointer to its previous value
    on each rejected statement.

            PR fortran/48776
            PR fortran/111291

    gcc/fortran/ChangeLog:

            * parse.cc: Restore current interface to its previous value on
error.

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

end of thread, other threads:[~2024-01-20 15:50 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-26 18:46 [Bug fortran/48776] New: ICE(segfault) after -std=f95 diagnostic error involving PROCEDURE burnus at gcc dot gnu.org
2013-06-16 13:13 ` [Bug fortran/48776] " dominiq at lps dot ens.fr
2023-08-26 18:29 ` mikael at gcc dot gnu.org
2023-08-26 18:30 ` mikael at gcc dot gnu.org
2023-08-26 19:47 ` mikael at gcc dot gnu.org
2023-08-30 12:20 ` cvs-commit at gcc dot gnu.org
2023-08-30 19:38 ` mikael at gcc dot gnu.org
2023-08-30 19:39 ` mikael at gcc dot gnu.org
2024-01-20 15:50 ` cvs-commit 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).