public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components
@ 2022-06-01 18:45 bourdin at mcmaster dot ca
  2022-06-16 12:53 ` [Bug fortran/105807] " marxin at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: bourdin at mcmaster dot ca @ 2022-06-01 18:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105807
           Summary: ICE / error when defining a class containing
                    polymorphic components
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bourdin at mcmaster dot ca
  Target Milestone: ---

defining a class whose components are polymorphic variables fails:

Consider the following (legal) source code:
module Vect_class
    type, abstract :: Vect_Type
    end type
end module Vect_class

module Elem_class
    use Vect_class
    type, abstract :: Elem_Type
        integer                      :: numDof
        class(Vect_type),allocatable :: v
    end type
end module Elem_class

module Vect
    use Vect_class

    type, extends(Vect_Type) :: Vect2D 
       real :: X,Y
    end type Vect2D   

    type, extends(Vect_Type) :: Vect3D 
       real :: X,Y,Z
    end type Vect3D   
end module Vect

module Elem
    use Elem_class

    type, extends(Elem_type)  :: elem2D
    end type
end module Elem

program testElem
    use Vect_class
    use Vect
    use Elem_class
    use Elem

    type(Vect2D) :: a
    type(Vect3D) :: b
    class(Vect_type),allocatable :: c,d
    class(Elem_type),allocatable :: e
    real       :: x,y,z

    x = 1.0
    y =-2.0
    z = 3.0

    a = Vect2D(x,y)
    b = Vect3D(x,y,z)
    c = Vect2D(x,y)
    d = Vect3D(x,y,z)
    e = Elem2D(10,b)
    write(*,*) e%numDof
end program testElem

It fails to compile with error message with GNU Fortran (GCC) 11.2.1 20210728
(Red Hat 11.2.1-1) (RHEL7 devtoolset 11)

   53 |     e = Elem2D(10,b)
      |                  1
Error: Cannot convert TYPE(vect3d) to CLASS(__class_vect_class_Vect_type_a) at
(1)

Under macOS (monterey, M1 processor) GNU Fortran (Homebrew GCC 11.3.0_1)
11.3.0, I get an ICE:

TestNestedClass3.f90:53:20:

   53 |     e = Elem2D(10,b)
      |                    1
internal compiler error: in fold_convert_loc, at fold-const.c:2563

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

* [Bug fortran/105807] ICE / error when defining a class containing polymorphic components
  2022-06-01 18:45 [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components bourdin at mcmaster dot ca
@ 2022-06-16 12:53 ` marxin at gcc dot gnu.org
  2022-06-21 18:48 ` gscfq@t-online.de
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-06-16 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-4464-g017665f63047ce47, it was rejected before the revision.

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

* [Bug fortran/105807] ICE / error when defining a class containing polymorphic components
  2022-06-01 18:45 [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components bourdin at mcmaster dot ca
  2022-06-16 12:53 ` [Bug fortran/105807] " marxin at gcc dot gnu.org
@ 2022-06-21 18:48 ` gscfq@t-online.de
  2022-06-23 15:38 ` gscfq@t-online.de
  2023-01-25  3:42 ` abensonca at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gscfq@t-online.de @ 2022-06-21 18:48 UTC (permalink / raw)
  To: gcc-bugs

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

G. Steinmetz <gscfq@t-online.de> changed:

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

--- Comment #2 from G. Steinmetz <gscfq@t-online.de> ---

Some simplified versions :


$ cat z1.f90
program p
    type, abstract :: t
    end type
    type, abstract :: t2
        integer :: n
        class(t), allocatable :: v
    end type
    type, extends(t2) :: elem2d
    end type
    type, extends(t) :: vect3d
    end type
    type(vect3d) :: b
    class(t2), allocatable :: e
    e = elem2d(10,b)
end program


$ cat z2.f90
program p
    type t
    end type
    type t2
        integer :: n
        class(t), allocatable :: v
    end type
    type, extends(t2) :: elem2d
    end type
    type, extends(t) :: vect3d
    end type
    type(vect3d) :: b
    class(t2), allocatable :: e
    e = elem2d(10,b)
end program


$ gfortran-13-20220619 -c z1.f90
z1.f90:14:20:

   14 |     e = elem2d(10,b)
      |                    1
internal compiler error: in fold_convert_loc, at fold-const.cc:2593
0x9c67b3 fold_convert_loc(unsigned int, tree_node*, tree_node*)
        ../../gcc/fold-const.cc:2593
0x7eb806 gfc_trans_subcomponent_assign
        ../../gcc/fortran/trans-expr.cc:9004
0x7ec3bb gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc/fortran/trans-expr.cc:9197
0x7ebec2 gfc_trans_subcomponent_assign
        ../../gcc/fortran/trans-expr.cc:9021
0x7ec3bb gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc/fortran/trans-expr.cc:9197
0x7e4970 gfc_conv_structure(gfc_se*, gfc_expr*, int)
        ../../gcc/fortran/trans-expr.cc:9264
0x7e4cfc gfc_conv_expr(gfc_se*, gfc_expr*)
        ../../gcc/fortran/trans-expr.cc:9432
0x7f5f91 gfc_trans_assignment_1
        ../../gcc/fortran/trans-expr.cc:11700
0x7b3b67 trans_code
        ../../gcc/fortran/trans.cc:1950
0x7dd0be gfc_generate_function_code(gfc_namespace*)
        ../../gcc/fortran/trans-decl.cc:7654
0x75f53e translate_all_program_units
        ../../gcc/fortran/parse.cc:6669
0x75f53e gfc_parse_file()
        ../../gcc/fortran/parse.cc:6956
0x7acb6f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.cc:229

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

* [Bug fortran/105807] ICE / error when defining a class containing polymorphic components
  2022-06-01 18:45 [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components bourdin at mcmaster dot ca
  2022-06-16 12:53 ` [Bug fortran/105807] " marxin at gcc dot gnu.org
  2022-06-21 18:48 ` gscfq@t-online.de
@ 2022-06-23 15:38 ` gscfq@t-online.de
  2023-01-25  3:42 ` abensonca at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gscfq@t-online.de @ 2022-06-23 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from G. Steinmetz <gscfq@t-online.de> ---

One tick simpler, without vect3d :

$ cat z3.f90
program p
    type t
    end type
    type t2
        class(t), allocatable :: v
    end type
    type, extends(t2) :: elem2d
    end type
    type(t) :: b
    class(t2), allocatable :: e
    e = elem2d(b)
end program


No ICE when b is replaced by constructor t() :

$ cat z5.f90
program p
    type t
    end type
    type t2
        class(t), allocatable :: v
    end type
    type, extends(t2) :: elem2d
    end type
    class(t2), allocatable :: e
    e = elem2d(t())
end program

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

* [Bug fortran/105807] ICE / error when defining a class containing polymorphic components
  2022-06-01 18:45 [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components bourdin at mcmaster dot ca
                   ` (2 preceding siblings ...)
  2022-06-23 15:38 ` gscfq@t-online.de
@ 2023-01-25  3:42 ` abensonca at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: abensonca at gcc dot gnu.org @ 2023-01-25  3:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Benson <abensonca at gcc dot gnu.org> ---
A possibly related case:

module tm

  type :: st
  end type st

  type :: resourceManager
     class  (*), pointer :: resource => null()
     integer   , pointer :: counter  => null()
  end type resourceManager

  interface resourceManager
     module procedure resourceManager
  end interface

  type :: wrap
     type(st), pointer :: obj => null()
     type(resourceManager) :: manager
  end type wrap

  interface wrap
     module procedure wrapConstructN
  end interface

contains

  function resourceManagerConstructor(resource) result(self)
    implicit none
    type(resourceManager) :: self
    class(*), intent(in   ), pointer :: resource

    self%resource => resource
    allocate(self%counter)
    self%counter=1
    return
  end function resourceManagerConstructor

  function wrapConstructN(i) result(self)
    implicit none
    type(wrap) :: self
    integer, intent(in   ) :: i
    type(st), pointer :: st_

    allocate(self%obj)
    self%obj=st()
    self%manager=resourceManager(self%obj)
    return
  end function wrapConstructN

end module tm

$ gfortran -c bug.F90 -o bug -g
bug.F90:45:42:

   45 |     self%manager=resourceManager(self%obj)
      |                                          1
internal compiler error: in fold_convert_loc, at fold-const.cc:2627
0x770b18 fold_convert_loc(unsigned int, tree_node*, tree_node*)
        ../../gcc-git-unpatched/gcc/fold-const.cc:2627
0xa65649 gfc_trans_subcomponent_assign
        ../../gcc-git-unpatched/gcc/fortran/trans-expr.cc:9053
0xa667c9 gfc_trans_structure_assign(tree_node*, gfc_expr*, bool, bool)
        ../../gcc-git-unpatched/gcc/fortran/trans-expr.cc:9246
0xa67531 gfc_conv_structure(gfc_se*, gfc_expr*, int)
        ../../gcc-git-unpatched/gcc/fortran/trans-expr.cc:9313
0xa6ae35 gfc_trans_assignment_1
        ../../gcc-git-unpatched/gcc/fortran/trans-expr.cc:11742
0xa1b307 trans_code
        ../../gcc-git-unpatched/gcc/fortran/trans.cc:1950
0xa4d81d gfc_generate_function_code(gfc_namespace*)
        ../../gcc-git-unpatched/gcc/fortran/trans-decl.cc:7674
0xa1f6d1 gfc_generate_module_code(gfc_namespace*)
        ../../gcc-git-unpatched/gcc/fortran/trans.cc:2370
0x9c73f5 translate_all_program_units
        ../../gcc-git-unpatched/gcc/fortran/parse.cc:6708
0x9c73f5 gfc_parse_file()
        ../../gcc-git-unpatched/gcc/fortran/parse.cc:7027
0xa1804f gfc_be_parse_file
        ../../gcc-git-unpatched/gcc/fortran/f95-lang.cc:229
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

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

end of thread, other threads:[~2023-01-25  3:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01 18:45 [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components bourdin at mcmaster dot ca
2022-06-16 12:53 ` [Bug fortran/105807] " marxin at gcc dot gnu.org
2022-06-21 18:48 ` gscfq@t-online.de
2022-06-23 15:38 ` gscfq@t-online.de
2023-01-25  3:42 ` abensonca 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).