public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
@ 2023-01-17 17:45 gscfq@t-online.de
  2023-01-17 20:01 ` [Bug fortran/108434] " anlauf at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gscfq@t-online.de @ 2023-01-17 17:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108434
           Summary: [12/13 Regression] ICE in class_allocatable, at
                    fortran/expr.cc:5000
           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 20211121 :
(with -g or a combination of -Wall -g -O2 -fopenmp -fopenacc)


$ cat z1.f90
program p
   type t
      class(c), pointer :: a(2)
   end type
   class(t), allocatable :: x
   class(t), pointer :: y
end


$ cat z2.f90
program p
   type t
      class(c), pointer :: a(2)
   end type
   class(t), pointer :: y
   class(t), allocatable :: x
end


$ gfortran-13-20230115 -c z2.f90 -g
z2.f90:3:31:

    3 |       class(c), pointer :: a(2)
      |                               1
Error: Pointer array component of structure at (1) must have a deferred shape
f951: internal compiler error: Segmentation fault
0xf8734f crash_signal
        ../../gcc/toplev.cc:314
0x83e346 class_allocatable
        ../../gcc/fortran/expr.cc:5000
0x83e346 comp_allocatable
        ../../gcc/fortran/expr.cc:5013
0x83e346 gfc_generate_initializer(gfc_typespec*, bool)
        ../../gcc/fortran/expr.cc:5157
0x8139d5 gfc_find_derived_vtab(gfc_symbol*)
        ../../gcc/fortran/class.cc:2460
0x8bea8d resolve_fl_derived
        ../../gcc/fortran/resolve.cc:15210
0x8b8057 resolve_symbol
        ../../gcc/fortran/resolve.cc:15595
0x8d7472 do_traverse_symtree
        ../../gcc/fortran/symbol.cc:4186
0x8bb624 resolve_types
        ../../gcc/fortran/resolve.cc:17547
0x8b6a9c gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.cc:17662
0x89e844 resolve_all_program_units
        ../../gcc/fortran/parse.cc:6656
0x89e844 gfc_parse_file()
        ../../gcc/fortran/parse.cc:6912
0x8ed3af gfc_be_parse_file
        ../../gcc/fortran/f95-lang.cc:229

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
@ 2023-01-17 20:01 ` anlauf at gcc dot gnu.org
  2023-01-18  8:46 ` marxin at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-01-17 20:01 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #1 from anlauf at gcc dot gnu.org ---
I cannot reproduce the ICE here, but valgrind tells me that something
is fishy here with error recovery that can be solved by the following
obvious patch:

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 5ec369c9cd8..9ab6b8eed86 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -4996,14 +4996,14 @@ get_union_initializer (gfc_symbol *union_type,
gfc_component **map_p)
 static bool
 class_allocatable (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.allocatable;
 }

 static bool
 class_pointer (gfc_component *comp)
 {
-  return comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  return comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA (comp)
     && CLASS_DATA (comp)->attr.pointer;
 }


However, playing some more, I get an ICE when changing in the bad type
declaration

     class(c), pointer :: a(2)

to

     class(c), allocatable :: a(2)

The traceback tells me that we might want to wait for Paul's finalization
fix...

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
  2023-01-17 20:01 ` [Bug fortran/108434] " anlauf at gcc dot gnu.org
@ 2023-01-18  8:46 ` marxin at gcc dot gnu.org
  2023-01-18  8:58 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-18  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |marxin at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-01-18

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
I think it's much older issue, 4.8.0 also reported "Invalid read of size"
valgrind issue.

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
  2023-01-17 20:01 ` [Bug fortran/108434] " anlauf at gcc dot gnu.org
  2023-01-18  8:46 ` marxin at gcc dot gnu.org
@ 2023-01-18  8:58 ` rguenth at gcc dot gnu.org
  2023-01-18 21:21 ` anlauf at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-18  8:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2023-01-18  8:58 ` rguenth at gcc dot gnu.org
@ 2023-01-18 21:21 ` anlauf at gcc dot gnu.org
  2023-01-19 18:23 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-01-18 21:21 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #3 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2023-January/058778.html

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2023-01-18 21:21 ` anlauf at gcc dot gnu.org
@ 2023-01-19 18:23 ` cvs-commit at gcc dot gnu.org
  2023-01-23 21:30 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-19 18:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:117848f425a3c0eda85517b4bdaf2ebe3bc705c2

commit r13-5260-g117848f425a3c0eda85517b4bdaf2ebe3bc705c2
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Jan 18 22:13:29 2023 +0100

    Fortran: error recovery for invalid CLASS component [PR108434]

    gcc/fortran/ChangeLog:

            PR fortran/108434
            * expr.cc (class_allocatable): Prevent NULL pointer dereference
            or invalid read.
            (class_pointer): Likewise.

    gcc/testsuite/ChangeLog:

            PR fortran/108434
            * gfortran.dg/pr108434.f90: New test.

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2023-01-19 18:23 ` cvs-commit at gcc dot gnu.org
@ 2023-01-23 21:30 ` cvs-commit at gcc dot gnu.org
  2023-01-23 21:39 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-01-23 21:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Harald Anlauf
<anlauf@gcc.gnu.org>:

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

commit r12-9059-gea99f8d0f6674de2c2f20a5bc3221ae6325032ea
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Jan 18 22:13:29 2023 +0100

    Fortran: error recovery for invalid CLASS component [PR108434]

    gcc/fortran/ChangeLog:

            PR fortran/108434
            * expr.cc (class_allocatable): Prevent NULL pointer dereference
            or invalid read.
            (class_pointer): Likewise.

    gcc/testsuite/ChangeLog:

            PR fortran/108434
            * gfortran.dg/pr108434.f90: New test.

    (cherry picked from commit 117848f425a3c0eda85517b4bdaf2ebe3bc705c2)

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2023-01-23 21:30 ` cvs-commit at gcc dot gnu.org
@ 2023-01-23 21:39 ` anlauf at gcc dot gnu.org
  2023-03-19 21:23 ` anlauf at gcc dot gnu.org
  2023-05-08 12:26 ` [Bug fortran/108434] [12/13/14 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-01-23 21:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from anlauf at gcc dot gnu.org ---
The reported issue should be fixed for gcc-13 and on 12-branch.

There is another potential issue (see comment#1) which might be related
to this one or not.  Keeping this PR open until the finalization work
reaches the next stage...

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

* [Bug fortran/108434] [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (6 preceding siblings ...)
  2023-01-23 21:39 ` anlauf at gcc dot gnu.org
@ 2023-03-19 21:23 ` anlauf at gcc dot gnu.org
  2023-05-08 12:26 ` [Bug fortran/108434] [12/13/14 " rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-03-19 21:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #6)
> There is another potential issue (see comment#1) which might be related
> to this one or not.  Keeping this PR open until the finalization work
> reaches the next stage...

The variant from comment#1 first hits a NULL pointer dereference fixed by:

diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc
index bffc0ffff3a..0436db82020 100644
--- a/gcc/fortran/class.cc
+++ b/gcc/fortran/class.cc
@@ -940,7 +940,7 @@ comp_is_finalizable (gfc_component *comp)
               || (comp->ts.u.derived->f2k_derived
                   && comp->ts.u.derived->f2k_derived->finalizers)))
     return true;
-  else if (comp->ts.type == BT_CLASS && CLASS_DATA (comp)
+  else if (comp->ts.type == BT_CLASS && comp->attr.class_ok && CLASS_DATA
(comp)
            && CLASS_DATA (comp)->attr.allocatable)
     return true;
   else

but afterwards generates a traceback in generate_finalization_wrapper:

pr108434-aa.f90:8:35:

    8 |      class(c), allocatable :: a(2) ! { dg-error "must have a deferred
shape" }
      |                                   1
Error: Allocatable component of structure at (1) must have a deferred shape
f951: internal compiler error: in generate_finalization_wrapper, at
fortran/class.cc:1714
0x8e10e1 generate_finalization_wrapper
        ../../gcc-trunk/gcc/fortran/class.cc:1714
0x8e4396 gfc_find_derived_vtab(gfc_symbol*)
        ../../gcc-trunk/gcc/fortran/class.cc:2618
0x9abfb8 resolve_fl_derived
        ../../gcc-trunk/gcc/fortran/resolve.cc:15482
0x9ad0af resolve_symbol
        ../../gcc-trunk/gcc/fortran/resolve.cc:15867
0x9d78d8 do_traverse_symtree
        ../../gcc-trunk/gcc/fortran/symbol.cc:4196
0x9d7996 gfc_traverse_ns(gfc_namespace*, void (*)(gfc_symbol*))
        ../../gcc-trunk/gcc/fortran/symbol.cc:4221
0x9b1f95 resolve_types
        ../../gcc-trunk/gcc/fortran/resolve.cc:17830
0x9b2446 gfc_resolve(gfc_namespace*)
        ../../gcc-trunk/gcc/fortran/resolve.cc:17945
0x97f916 resolve_all_program_units
        ../../gcc-trunk/gcc/fortran/parse.cc:6655
0x980112 gfc_parse_file()
        ../../gcc-trunk/gcc/fortran/parse.cc:6911
0x9e779f gfc_be_parse_file
        ../../gcc-trunk/gcc/fortran/f95-lang.cc:229

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

* [Bug fortran/108434] [12/13/14 Regression] ICE in class_allocatable, at fortran/expr.cc:5000
  2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
                   ` (7 preceding siblings ...)
  2023-03-19 21:23 ` anlauf at gcc dot gnu.org
@ 2023-05-08 12:26 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #8 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] 10+ messages in thread

end of thread, other threads:[~2023-05-08 12:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 17:45 [Bug fortran/108434] New: [12/13 Regression] ICE in class_allocatable, at fortran/expr.cc:5000 gscfq@t-online.de
2023-01-17 20:01 ` [Bug fortran/108434] " anlauf at gcc dot gnu.org
2023-01-18  8:46 ` marxin at gcc dot gnu.org
2023-01-18  8:58 ` rguenth at gcc dot gnu.org
2023-01-18 21:21 ` anlauf at gcc dot gnu.org
2023-01-19 18:23 ` cvs-commit at gcc dot gnu.org
2023-01-23 21:30 ` cvs-commit at gcc dot gnu.org
2023-01-23 21:39 ` anlauf at gcc dot gnu.org
2023-03-19 21:23 ` anlauf at gcc dot gnu.org
2023-05-08 12:26 ` [Bug fortran/108434] [12/13/14 " rguenth 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).