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

IFORT fails to properly allocate dummy argument with assumed length parameter

Cristian_P_
Beginner
341 Views

Here is a program demonstrating the run-time error mentioned in the title.  I believe this is a bug in IFORT 16.0.0

Program test
   Implicit None

   Type string(slen)
      Integer, Len :: slen
      Character    :: its_value(slen)
   End Type string

   Type(string(5)), Dimension(:), Allocatable :: my_string1
   Type(string(5)), Dimension(:), Allocatable :: my_string2

   Integer :: stat

   Call allocate_string(my_string1)
   If(Allocated(my_string1)) Then
      Print '(a, 1i1)', "my_string1 was allocated with len = ", my_string1%slen
      Deallocate(my_string1, Stat = stat)
   End If

   Print *
   If(stat /= 0) Then
      Print '(a)', "Something is wrong, because"
      Print '(a, i3)', "deallocation of my_string1 failed with status ", stat
   End If
   Print *

   !The problem appears to be the value of the assumed length parameter slen inside the
   !Allocate statement of the subroutine allocate_string.  If we do the allocation outside,
   !then the interface of allocate_string seems to properly transfer the value
   !of the assumed length parameter slen in and out the body of the subroutine 

   Allocate(string(5) :: my_string2(3))
   Call allocate_string(my_string2)

Contains

   Subroutine allocate_string(my_string)
      Type(string(*)), Dimension(:), Allocatable, Intent(InOut) :: my_string

      ! If needed, perform typed allocation with the string len parameter being assumed
      If(.Not.Allocated(my_string)) Allocate(string(*) :: my_string(3))

      Print '(a     )', "I am supposed to print 5"
      Print '(a, 1i1)', "I am printing          ",  my_string%slen

   End Subroutine allocate_string

End Program test

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
341 Views

Thanks, we'll take a look.

0 Kudos
Steven_L_Intel1
Employee
341 Views

Escalated as issue DPD200380620 - thanks for the nice test case.

0 Kudos
Reply