Bug 44465 - [OOP] ICE with polymorphic object oriented example
Summary: [OOP] ICE with polymorphic object oriented example
Status: RESOLVED DUPLICATE of bug 44211
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-06-08 10:11 UTC by Ian Chivers
Modified: 2010-06-09 15:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-08 13:53:33


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Chivers 2010-06-08 10:11:42 UTC
We are developing object oriented examples for our next book and have hit a compiler bug with the following short program. 

program polymorphic

use shape_module
use circle_module
use rectangle_module

implicit none

type shape_w
  class (shape_type) , allocatable :: shape_v
end type shape_w

type (shape_w) , dimension(3) :: p

  print *,' shape '

  p(1)%shape_v=shape_type(10,20)
  call p(1)%shape_v%draw()

  print *,' circle '

  p(2)%shape_v=circle_type(100,200,300)
  call p(2)%shape_v%draw()

  print *,' rectangle '

  p(3)%shape_v=rectangle_type(1000,2000,3000,4000)
  call p(3)%shape_v%draw()

end program polymorphic

The following example program compiles and runs.

program polymorphic

use shape_module
use circle_module
use rectangle_module

implicit none

class (shape_type)     , allocatable :: p

  allocate(shape_type :: p)

  print *,' ** shape **'

  p=shape_type(10,20)
  call p%draw()

  print *,' ** circle **'

  p=circle_type(100,200,300)
  call p%draw()

  print *,' ** rectangle **'

  p=rectangle_type(1000,2000,3000,4000)
  call p%draw()

end program polymorphic

Here is the rest of the information requested in the bug report
document.

gcc version
-----------

c:\document\fortran\newbook\examples\ch32>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/program files (x86)/gfortran/bin/../libexec/gcc/i586-pc-mingw32/4.6.0/lto-wrapper.exe
Target: i586-pc-mingw32
Configured with: ../gcc-trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/brad/gfortran/dependencies -
-disable-werror --enable-threads --disable-nls --build=i586-pc-mingw32 --enable-libgomp --disable-shared --disable-win32-registry
--with-dwarf2 --disable-sjlj-exceptions : (reconfigured) ../gcc-trunk/configure --prefix=/mingw --enable-languages=c,fortran --wit
h-gmp=/home/brad/gfortran/dependencies --disable-werror --enable-threads --disable-nls --build=i586-pc-mingw32 --enable-libgomp --
disable-shared --disable-win32-registry --with-dwarf2 --disable-sjlj-exceptions
Thread model: win32
gcc version 4.6.0 20100524 (experimental) [trunk revision 159774] (GCC)

Hardware and Operating system
-----------------------------

The information below is from the Intel
CPU id utility.

++++++++++++++++++++++++++++++++++++++++++

Intel(R) Processor Identification Utility
Version: 4.22.20100224
Time Stamp: 2010/06/08 09:48:20
Operating System: 6.0-6002-Service Pack 2
Number of processors in system: 1
Current processor: #1
Active cores per processor: 4
Disabled cores per processor: 0
Processor Name: Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz

stuff deleted

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The system is running 

  Windows Vista Home Premium SP2 - 64 Bit.

gcc build options
=================

I did not build it I just took the gfortran executable
from the download site.

Compiler command line
=====================


c:\document\fortran\newbook\examples\ch32>gfortran shape_p.f90 circle_p.f90 rectangle_p.f90 polymorph_array.f90
polymorph_array.f90: In function 'polymorphic':
polymorph_array.f90:18:0: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Do you want the shape_p.f90, circle_p.f90 and rectangle_p.f90
source files?
Comment 1 Tobias Burnus 2010-06-08 13:00:38 UTC
(In reply to comment #0)
> c:\document\fortran\newbook\examples\ch32>gfortran shape_p.f90 circle_p.f90
> rectangle_p.f90 polymorph_array.f90
> polymorph_array.f90: In function 'polymorphic':
> polymorph_array.f90:18:0: internal compiler error: Segmentation fault


> Do you want the shape_p.f90, circle_p.f90 and rectangle_p.f90
> source files?

Yes, please. Without it is difficult to reproduce the segfault. Please attach the modules (unless they are short, then you can also paste them) - probably best by putting all modules into a single file (rather than attaching them one by one, which is also fine).

Thanks for the bug report!
Comment 2 Ian Chivers 2010-06-08 13:21:40 UTC
Subject: RE:  [OOP] ICE with polymorphic object oriented example

I should have included them  with the bug report!
Things are really progressing with the compiler.
Well done!
Out of the compilers Jane and I have access to
The only one that compiles them is the nag compiler.

Cheers

Ian Chivers

Files are

Shape_p.f90

module shape_module

  type shape_type
    integer   :: x_=0
    integer   :: y_=0
    contains
    procedure , pass(this) :: getx
    procedure , pass(this) :: gety
    procedure , pass(this) :: setx
    procedure , pass(this) :: sety
    procedure , pass(this) :: moveto
    procedure , pass(this) :: draw
  end type shape_type

interface assignment(=)
  module procedure generic_shape_assign
end interface

contains

  integer function getx(this)
    implicit none
    class (shape_type) , intent(in) :: this
    getx=this%x_
  end function getx

  integer function gety(this)
    implicit none
    class (shape_type) , intent(in) :: this
    gety=this%y_
  end function gety

  subroutine setx(this,x)
    implicit none
    class (shape_type), intent(inout) :: this
    integer , intent(in) :: x
    this%x_=x
  end subroutine setx

  subroutine sety(this,y)
    implicit none
    class (shape_type), intent(inout) :: this
    integer , intent(in) :: y
    this%y_=y
  end subroutine sety

  subroutine moveto(this,newx,newy)
    implicit none
    class (shape_type), intent(inout) :: this
    integer , intent(in) :: newx
    integer , intent(in) :: newy
    this%x_=newx
    this%y_=newy
  end subroutine moveto

  subroutine draw(this)
    implicit none
    class (shape_type), intent(in) :: this
    print *,' x = ' , this%x_
    print *,' y = ' , this%y_
  end subroutine draw

  subroutine generic_shape_assign(lhs,rhs)
  implicit none
    class (shape_type) , intent(out) , allocatable :: lhs
    class (shape_type) , intent(in) :: rhs
      print *,' In generic_shape_assign'
      if ( allocated(lhs) ) then
        deallocate(lhs)
      end if
      allocate(lhs,source=rhs)
  end subroutine generic_shape_assign
  
end module shape_module

Circle_p.f90

module circle_module

use shape_module

type , extends(shape_type) :: circle_type

  integer :: radius_

  contains

  procedure , pass(this) :: getradius
  procedure , pass(this) :: setradius
  procedure , pass(this) :: draw => draw_circle

end type circle_type

  contains

  integer function getradius(this)
  implicit none
  class (circle_type) , intent(in) :: this
    getradius=this%radius_
  end function getradius

  subroutine setradius(this,radius)
  implicit none
  class (circle_type) , intent(inout) :: this
  integer , intent(in) :: radius
    this%radius_=radius
  end subroutine setradius

  subroutine draw_circle(this)
  implicit none
    class (circle_type), intent(in) :: this
    print *,' x = ' , this%x_
    print *,' y = ' , this%y_
    print *,' radius = ' , this%radius_
  end subroutine draw_circle

end module circle_module


Rectangle_p.f90

module rectangle_module

use shape_module

type , extends(shape_type) :: rectangle_type

  integer :: width_
  integer :: height_

  contains

  procedure , pass(this) :: getwidth
  procedure , pass(this) :: setwidth
  procedure , pass(this) :: getheight
  procedure , pass(this) :: setheight
  procedure , pass(this) :: draw => draw_rectangle

end type rectangle_type

  contains

  integer function getwidth(this)
  implicit none
  class (rectangle_type) , intent(in) :: this
    getwidth=this%width_
  end function getwidth

  subroutine setwidth(this,width)
  implicit none
  class (rectangle_type) , intent(inout) :: this
  integer , intent(in) :: width
    this%width_=width
  end subroutine setwidth

  integer function getheight(this)
  implicit none
  class (rectangle_type) , intent(in) :: this
    getheight=this%height_
  end function getheight

  subroutine setheight(this,height)
  implicit none
  class (rectangle_type) , intent(inout) :: this
  integer , intent(in) :: height
    this%height_=height
  end subroutine setheight

  subroutine draw_rectangle(this)
  implicit none
    class (rectangle_type), intent(in) :: this
    print *,' x = ' , this%x_
    print *,' y = ' , this%y_
    print *,' width = ' , this%width_
    print *,' height = ' , this%height_

  end subroutine draw_rectangle

end module rectangle_module

> -----Original Message-----
> From: burnus at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org]
> Sent: 08 June 2010 14:01
> To: ian@rhymneyconsulting.co.uk
> Subject: [Bug fortran/44465] [OOP] ICE with polymorphic object oriented
> example
> 
> 
> 
> ------- Comment #1 from burnus at gcc dot gnu dot org  2010-06-08 13:00
> -------
> (In reply to comment #0)
> > c:\document\fortran\newbook\examples\ch32>gfortran shape_p.f90
> circle_p.f90
> > rectangle_p.f90 polymorph_array.f90
> > polymorph_array.f90: In function 'polymorphic':
> > polymorph_array.f90:18:0: internal compiler error: Segmentation fault
> 
> 
> > Do you want the shape_p.f90, circle_p.f90 and rectangle_p.f90
> > source files?
> 
> Yes, please. Without it is difficult to reproduce the segfault. Please
> attach
> the modules (unless they are short, then you can also paste them) -
> probably
> best by putting all modules into a single file (rather than attaching
> them one
> by one, which is also fine).
> 
> Thanks for the bug report!
> 
> 
> --
> 
> burnus at gcc dot gnu dot org changed:
> 
>            What    |Removed                     |Added
> -----------------------------------------------------------------------
> -----
>                  CC|                            |janus at gcc dot gnu
> dot org
>             Summary|polymorphic object oriented |[OOP] ICE with
> polymorphic
>                    |example                     |object oriented
> example
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44465
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.

Comment 3 Tobias Burnus 2010-06-08 13:53:33 UTC
Valgrind shows:

==26969== Invalid read of size 4
==26969==    at 0x553131: gfc_conv_scalarized_array_ref (trans-array.c:2494)
==26969==    by 0x553824: gfc_conv_array_ref (trans-array.c:2547)
==26969==    by 0x572CE0: gfc_conv_variable (trans-expr.c:698)
==26969==    by 0x56F8E9: gfc_conv_procedure_call (trans-expr.c:1523)
==26969==    by 0x58CF62: gfc_trans_call (trans-stmt.c:375)
Comment 4 janus 2010-06-08 14:22:24 UTC
Actually this seems to be a duplicate of PR 44211. It is fixed by the patch I submitted yesterday:

http://gcc.gnu.org/ml/fortran/2010-06/msg00060.html

The patch has been approved by Tobias, and I will commit it once the trunk is unfrozen again.


*** This bug has been marked as a duplicate of 44211 ***
Comment 5 Tobias Burnus 2010-06-09 15:07:15 UTC
With the patch for PR 44211 (just committed to the 4.6 trunk), the program compiles and the output is:

  shape
  In generic_shape_assign
  x =           10
  y =           20
  circle
  In generic_shape_assign
  x =          100
  y =          200
  radius =          300
  rectangle
  In generic_shape_assign
  x =         1000
  y =         2000
  width =         3000
  height =         4000

Thanks again for the bug report!
Comment 6 Ian Chivers 2010-06-09 15:20:52 UTC
Subject: RE:  [OOP] ICE with polymorphic object oriented example

Thanks very much for fixing it.

Cheers

Ian

> -----Original Message-----
> From: burnus at gcc dot gnu dot org [mailto:gcc-bugzilla@gcc.gnu.org]
> Sent: 09 June 2010 16:07
> To: ian@rhymneyconsulting.co.uk
> Subject: [Bug fortran/44465] [OOP] ICE with polymorphic object oriented
> example
> 
> 
> 
> ------- Comment #5 from burnus at gcc dot gnu dot org  2010-06-09 15:07
> -------
> With the patch for PR 44211 (just committed to the 4.6 trunk), the
> program
> compiles and the output is:
> 
>   shape
>   In generic_shape_assign
>   x =           10
>   y =           20
>   circle
>   In generic_shape_assign
>   x =          100
>   y =          200
>   radius =          300
>   rectangle
>   In generic_shape_assign
>   x =         1000
>   y =         2000
>   width =         3000
>   height =         4000
> 
> Thanks again for the bug report!
> 
> 
> --
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44465
> 
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
> You reported the bug, or are watching the reporter.