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

Issue with ALLOCATE(..., SOURCE=...) and polymorphic array slices

thomas_boehme
New Contributor II
441 Views

I experience unexpected behavior when allocating a polymorphic array from a part of another polymorphic array. I have added a fully working program demonstrating the problem.

In both cases, I would have expected to get a TargetItems array with 5 elements. But in the first case, I get an array with 10 elements, i.e. the full size of the SourceItems array.

I have seen this behavior with the latest IVF 17.0.0.109 as well as several previous versions.

Another issue: In the debugger (using IVF 17 and VS 2015 Update 3), all arrays are shown as undefined even after the allocate...

Best regards,

Thomas

  program AllocateSourceIssueWithArraySlice

   implicit none

    type :: baseType
      integer aValue
    end type
  
    
      class (baseType), ALLOCATABLE :: SourceItems(:)
      class (baseType), ALLOCATABLE :: TargetItems(:)
    
      ALLOCATE( baseType::SourceItems(10))
  
      print *, 'Allocating with arrayslice in SOURCE= statement'
    
      ALLOCATE( TargetItems, SOURCE=SourceItems(1:5) )
         
      print *, 'Size SourceItems (expected 10): ', SIZE(SourceItems)
      print *, 'Size TargetItems (expected 5):  ', SIZE(TargetItems)
    
    
      DEALLOCATE(TargetItems)
      print *, 'Allocating with arrayslice via assosciate construct'
    
    
      ASSOCIATE (Source => SourceItems(1:5))
      ALLOCATE( TargetItems, SOURCE=Source )
      END ASSOCIATE
    
      print *, 'Size SourceItems (expected 10): ', SIZE(SourceItems)
      print *, 'Size TargetItems (expected 5):  ', SIZE(TargetItems)
    
      end program

0 Kudos
4 Replies
Steven_L_Intel1
Employee
441 Views

Thanks - escalated as issue DPD200414141. Interesting that if the source array is not polymorphic, it works correctly.

0 Kudos
Steven_L_Intel1
Employee
441 Views

The fix for this might not make Update 1, but if not, definitely Update 2.

0 Kudos
thomas_boehme
New Contributor II
441 Views

Steve Lionel (Intel) wrote:

The fix for this might not make Update 1, but if not, definitely Update 2.

Thanks for the update on this issue.

Steve, in my original post I also mentioned that I am unable to see the variables in the above program in the debugger (VS2015 Update 3/IVF 17). Is that something specific to my installation or do have this issue as well? 

0 Kudos
Steven_L_Intel1
Employee
441 Views

The debugger issue is unrelated - the debugger still has problems with polymorphic variables. I will check with our debugger folk to make sure they're aware of this (DPD200414790).

0 Kudos
Reply