Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29010 Discussions

Parameterized derived type: unexpected run-time error with ALLOCATABLE type with a contained type

FortranFan
Honored Contributor III
1,067 Views

I believe the following code is ok and it compiles with no errors or warnings.  But it encounters a run-time error; it appears the automatic variable in the "contained" type that depends on the length parameter is not allocated.

module m

   implicit none

   private

   type :: t(n)
      private
      integer, len :: n = 1
      integer :: m_a(n)
   end type t

   type, public :: q(l)
      private
      integer, len :: l = 1
      type(t(n=l)) :: m_t
   end type q
   
   public :: init_q 
   
contains

   subroutine init_t(this)

      type(t(*)), intent(inout) :: this

      this%m_a = 1
      
      print *, " t%a = ", this%m_a

      return

   end subroutine init_t

   subroutine init_q(this)

      type(q(*)), intent(inout) :: this

      call init_t(this%m_t)

      return

   end subroutine init_q

end module m
program p

   use m, only : q, init_q

   type(q(l=:)), allocatable :: foo

   allocate( q(l=2) :: foo)
   call init_q(foo)

   stop

end program p

Upon execution,

forrtl: severe (157): Program Exception - access violation
Image              PC                Routine            Line        Source

p64.exe            000000013F8610F7  M_mp_INIT_T                27  m.f90
p64.exe            000000013F86125B  M_mp_INIT_Q                39  m.f90
p64.exe            000000013F861585  MAIN__                      8  p.f90
p64.exe            000000013F8F319E  Unknown               Unknown  Unknown
p64.exe            000000013F8F392C  Unknown               Unknown  Unknown
p64.exe            000000013F8F3A6E  Unknown               Unknown  Unknown
kernel32.dll       00000000772359ED  Unknown               Unknown  Unknown
ntdll.dll          000000007736BA01  Unknown               Unknown  Unknown
Press any key to continue . . .

 

0 Kudos
8 Replies
FortranFan
Honored Contributor III
1,067 Views

To stress the point about the ALLOCATABLE attribute, the program works without it.

program p

   use m, only : q, init_q

   type(q(l=2)) :: foo

   call init_q(foo)

   stop

end program p
  t%a =  1 1
Press any key to continue . . .

 

My apologies if this is a known issue; I couldn't be figure out for sure from the forum if an incident along these lines has been submitted.

0 Kudos
FortranFan
Honored Contributor III
1,067 Views

Here's a variation of the above problem with an extended type: please note the comment on line 25.

module m

   implicit none

   private

   type :: t(n)
      private
      integer, len :: n = 1
      integer :: m_a(n)
   end type t

   type, extends(t), public :: q
      private
   end type q
   
   public :: init_q 
   
contains

   subroutine init_q(this)

      type(q(*)), intent(inout) :: this

      this%m_a = 1    !.. this%t%m_a = 1 works.
      
      return

   end subroutine init_q

end module m
program p

   use m, only : q, init_q

   type(q(n=:)), allocatable :: foo

   allocate( q(n=2) :: foo )
   call init_q(foo)

   stop

end program p
forrtl: severe (157): Program Exception - access violation
Image              PC                Routine            Line        Source

p64.exe            000000013F5E10CD  M_mp_INIT_Q                25  m.f90
p64.exe            000000013F5E135C  MAIN__                      8  p.f90
p64.exe            000000013F66BF4E  Unknown               Unknown  Unknown
p64.exe            000000013F66C6DC  Unknown               Unknown  Unknown
p64.exe            000000013F66C81E  Unknown               Unknown  Unknown
kernel32.dll       00000000772359ED  Unknown               Unknown  Unknown
ntdll.dll          000000007736BA01  Unknown               Unknown  Unknown
Press any key to continue . . .

 

0 Kudos
FortranFan
Honored Contributor III
1,067 Views

Please note another variation of the extended type case in Quote #3.  With a statically declared variable, the program simply crashes without any run-time error:

program p

   use m, only : q, init_q  !.. module m as in Quote #3; q is an extended type

   type(q(n=2)) :: foo

   call init_q(foo)

   stop

end program p

crash_0.png

0 Kudos
FortranFan
Honored Contributor III
1,067 Views

Just trying to prevent this from falling off the radar; potentially a couple of issues with Intel Fortran compiler here.

0 Kudos
Steven_L_Intel1
Employee
1,067 Views

Whoops - thanks for the reminder. Will look at this tomorrow.

0 Kudos
Steven_L_Intel1
Employee
1,067 Views

Escalated as issue DPD200368557, and I included all variants. Thanks again.

0 Kudos
FortranFan
Honored Contributor III
1,067 Views

Thanks much, Steve.

I am hoping the fixes for such issues will extend to type-bound procedures as well (you'll note the procedures in the snippets above are not type-bound).  What I have posted here are the stripped down variants where the type binding has been removed, something I was trying out to further simplify the test cases.  Since the run-time behavior appeared to be the same with or without type binding, I didn't bother submitting type-bound scenarios.  Now I can test for this when the fixed releases become available, but it will be cool if the Intel development would be so kind to look into it during their resolution phase itself!

0 Kudos
Steven_L_Intel1
Employee
1,067 Views

Type-bound procedures are really a completely different thing in the compiler, not that they're without issues on their own.

But when I see a fix internally for the PDT issues, I'll try some cases with TBPs and see if I can break them.

0 Kudos
Reply