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

--- Comment #14 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Jürgen Reuter from comment #13)
> I confirm that with that patch our code compiles again, however, more or
> less all functionality fails because of runtime errors about 
> Fortran runtime error: Pointer actual argument '<some_name>' is not
> associated.
> Not sure whether this is related. Shall I open another PR? 
> Working on a reproducer for that problem.

Please work on a reproducer. I cannot quite see that the new problem is related
but keep this PR open for now.

The test below works, so the correct functionality of allocate is retained.
Your original reproducer no longer ICEs and gives the correct runtime error.

Cheers

Paul

! { dg-do compile }
! { dg-options "-fcheck=mem" }
!
! Test the fix for PR99545, in which the allocate statements caused an ICE.
!
! Contributed by Juergen Reuter  <juergen.reu...@desy.de>
!
module commands
  implicit none
!  private

  type, abstract :: range_t
     integer :: step_mode = 0
     integer :: n_step = 0
  end type range_t

  type, extends (range_t) :: range_int_t
     integer :: i_step = 1
  end type range_int_t

  type, extends (range_t) :: range_real_t
     real :: lr_step = 2.0
end type range_real_t

  type :: cmd_scan_t
!     private
     class(range_t), dimension(:), allocatable :: range
   contains
     procedure :: compile => cmd_scan_compile
  end type cmd_scan_t

contains

  subroutine cmd_scan_compile (cmd, sw)
    class(cmd_scan_t), intent(inout) :: cmd
    integer :: sw

    if (allocated (cmd%range)) deallocate (cmd%range)
    if (sw .eq. 1) then
      allocate (range_int_t :: cmd%range (3))
    else
      allocate (range_real_t :: cmd%range (3))
    end if
  end subroutine cmd_scan_compile

end module commands

  use commands
  class(cmd_scan_t), allocatable :: x
  integer :: i
  allocate (x)
  do i = 1, 2
    call x%compile (i)
    select type (y => x%range)
      type is (range_int_t)
        print *, y%i_step
      type is (range_real_t)
        print *, y%lr_step
    end select
  end do
end

Reply via email to