Bug 44864 - [OOP] ICE: Segmentation fault
Summary: [OOP] ICE: Segmentation fault
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.1
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2010-07-08 02:16 UTC by David Car
Modified: 2016-11-16 17:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.6.0
Known to fail: 4.5.1
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Car 2010-07-08 02:16:07 UTC
This code generates an internal compiler error (the same code as in Bug Report 44863 but with certain lines uncommented):


!================================================================================                
module BaseStrategy

  type, public, abstract :: Strategy
   contains
     procedure(strategy_update), pass( this ), deferred :: update
     procedure(strategy_pre_update), pass( this ), deferred :: preUpdate
     procedure(strategy_post_update), pass( this ), deferred :: postUpdate
  end type Strategy

  abstract interface
     subroutine strategy_update( this )
       import Strategy
       class (Strategy), target, intent(in) :: this
     end subroutine strategy_update
  end interface

  abstract interface
     subroutine strategy_pre_update( this )
       import Strategy
       class (Strategy), target, intent(in) :: this
     end subroutine strategy_pre_update
  end interface

  abstract interface
     subroutine strategy_post_update( this )
       import Strategy
       class (Strategy), target, intent(in) :: this
     end subroutine strategy_post_update
  end interface

end module BaseStrategy

!================================================================================                
module LaxWendroffStrategy

  use BaseStrategy

  private :: update, preUpdate, postUpdate

  type, public, extends( Strategy ) :: LaxWendroff
     class (Strategy), pointer :: child => null()
     contains
       procedure, pass( this ) :: update
       procedure, pass( this ) :: preUpdate
       procedure, pass( this ) :: postUpdate
  end type LaxWendroff

contains

  subroutine update( this )
    class (LaxWendroff), target, intent(in) :: this

    print *, 'Calling LaxWendroff update'
  end subroutine update

  subroutine preUpdate( this )
    class (LaxWendroff), target, intent(in) :: this

    print *, 'Calling LaxWendroff preUpdate'
  end subroutine preUpdate

  subroutine postUpdate( this )
    class (LaxWendroff), target, intent(in) :: this

    print *, 'Calling LaxWendroff postUpdate'
  end subroutine postUpdate

end module LaxWendroffStrategy


!================================================================================                
module KEStrategy

  use BaseStrategy
  ! Uncomment the line below and it runs fine                                                    
  ! use LaxWendroffStrategy                                                                      

  private :: update, preUpdate, postUpdate

  type, public, extends( Strategy ) :: KE
     class (Strategy), pointer :: child => null()
     contains
       procedure, pass( this ) :: update
       procedure, pass( this ) :: preUpdate
       procedure, pass( this ) :: postUpdate
  end type KE

contains

  subroutine init( this, other )
    class (KE), intent(inout) :: this
    class (Strategy), target, intent(in) :: other

    this % child => other
  end subroutine init

  subroutine update( this )
    class (KE), target, intent(in) :: this

    if ( associated( this % child ) ) then
       call this % child % update()
    end if

    print *, 'Calling KE update'
  end subroutine update


 subroutine preUpdate( this )
    class (KE), target, intent(in) :: this

    if ( associated( this % child ) ) then
       call this % child % preUpdate()
    end if

    print *, 'Calling KE preUpdate'
  end subroutine preUpdate

  subroutine postUpdate( this )
    class (KE), target, intent(in) :: this

    if ( associated( this % child ) ) then
       call this % child % postUpdate()
    end if

    print *, 'Calling KE postUpdate'
  end subroutine postUpdate

end module KEStrategy

!================================================================================                
program main

  use LaxWendroffStrategy
  use KEStrategy

  type :: StratSeq
     class (Strategy), pointer :: strat => null()
  end type StratSeq

  type (LaxWendroff), target :: lw_strat
  type (KE), target :: ke_strat

  type (StratSeq), allocatable, dimension( : ) :: seq

  allocate( seq(10) )

  call init( ke_strat, lw_strat )
  call ke_strat % preUpdate()
  call ke_strat % update()
  call ke_strat % postUpdate()

  seq( 1 ) % strat => ke_strat
  seq( 2 ) % strat => lw_strat

  call seq( 1 ) % strat % update()

  do i = 1, 2
     call seq( i ) % strat % update()
  end do

end program main
Comment 1 Tobias Burnus 2010-07-08 07:26:06 UTC
Same solution as in PR 44863: I can reproduce the problem in 4.5, but updating to 4.6 works. Both PRs are kind of a duplicate of PR 41829.

As written: 4.6 binaries are available at http://gcc.gnu.org/wiki/GFortranBinaries

For the implementation/bug status, see http://gcc.gnu.org/wiki/GFortranBinaries


Thanks nevertheless for reporting the bug.
Comment 2 David Car 2010-07-09 02:01:57 UTC
(In reply to comment #1)
> Same solution as in PR 44863: I can reproduce the problem in 4.5, but updating
> to 4.6 works. Both PRs are kind of a duplicate of PR 41829.
> 
> As written: 4.6 binaries are available at
> http://gcc.gnu.org/wiki/GFortranBinaries
> 
> For the implementation/bug status, see http://gcc.gnu.org/wiki/GFortranBinaries
> 
> 
> Thanks nevertheless for reporting the bug.
> 

Just built the 4.6 snapshot and reconfirmed that it works splendidly.  Thanks for all your efforts.
Comment 3 janus 2010-07-10 08:38:33 UTC
Closing as fixed.