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

Wrong array size with realloc_lhs when a type contains a allocatable class component

thomas_boehme
New Contributor II
647 Views

We have a large F2003 code that runs fine on IVF12.1 but always caused unexpected behavior on IVF13.x (and also the beta IVF14.x).

After quite a long search, we were able to attribute the problem to a (in my understanding) incorrect behavior when automatically reallocating the LHS of an array assignment.

I have a attached a (minimal?) demonstrator for that issue. It needs to be compiled with F2003 semantics enabled (or realloc_lhs).

I would expect that both reallocated arrays (Target...) should have size 5, however, after assignment the TargetArrayWithAllocatableClass has the full size of the src, and not just the first 5 elements.

The bug also disappers when changing the class(ATYPE), ALLOCATABLE to a class(ATYPE), POINTER.

Best regards, Thomas

[fortran]


module classdefs

type :: AType
real :: dummy
end type

type :: ClassWithAllocatableClassComponent
class (AType), ALLOCATABLE :: dummy
end type

type :: ClassWithAllocatableTypeComponent
type (AType), ALLOCATABLE :: dummy
end type

type PtrToClassWithAllocatableClassComponent
type (ClassWithAllocatableClassComponent), POINTER :: ptr
end type
type PtrToClassWithAllocatableTypeComponent
type (ClassWithAllocatableTypeComponent), POINTER :: ptr
end type

end module

program AllocatableClassComponentBug
use classdefs
implicit none

! Variables
type (PtrToClassWithAllocatableClassComponent), ALLOCATABLE :: SrcArrayWithAllocatableClass(:)
type (PtrToClassWithAllocatableTypeComponent), ALLOCATABLE :: SrcArrayWithAllocatableType(:)
type (PtrToClassWithAllocatableClassComponent), ALLOCATABLE :: TargetArrayWithAllocatableClass(:)
type (PtrToClassWithAllocatableTypeComponent), ALLOCATABLE :: TargetArrayWithAllocatableType(:)
integer i

ALLOCATE(SrcArrayWithAllocatableClass(10))
ALLOCATE(SrcArrayWIthAllocatableType(10))

TargetArrayWithAllocatableClass = SrcArrayWithAllocatableClass(1:5)
TargetArrayWithAllocatableType = SrcArrayWithAllocatableType(1:5)

PRINT *, 'Expected size for both Targets is 5'
PRINT *, 'Actual size for TargetArrayWithAllocatableClass is ', size(TargetArrayWithAllocatableClass)
PRINT *, 'Actual size for TargetArrayWithAllocatableType is ', size(TargetArrayWithAllocatableType)

end program AllocatableClassComponentBug

[/fortran]

0 Kudos
7 Replies
thomas_boehme
New Contributor II
647 Views

I have just seen that the above issue is likely related to issue DPD200243378 posten in the Linux forum a few days ago.

0 Kudos
IanH
Honored Contributor II
647 Views

For what it is worth: allocatable polymorphic components require considerable "care" when working with current/recent ifort.  I've been able to get by replacing assignments with ALLOCATE(lhs%alloc_poly_component, SOURCE=rhs%alloc_poly_component) once that was supported.  Dancing on a pin head while facing north and juggling six open bottles of wine also helps, or failing that, just drink the wine.

I put some test cases together in this thread here.

0 Kudos
Steven_L_Intel1
Employee
647 Views

It is not entirely clear to me that this is the same as Ian's issue, I'm pretty sure it's not the 244378 issue. But there is probably some commonality here.  I will report this to the developers - thanks for the example - I decided to attach it to DPD200236021 (Ian's)

0 Kudos
jimdempseyatthecove
Honored Contributor III
647 Views

IanH,

Have you posted a link of you on Youtube of you dancing on a pin head while facing north and juggling six open bottles of wine.

I'd like to see it.

Jim ;)

0 Kudos
Steven_L_Intel1
Employee
647 Views

The developers tell me that this is not the same as the earlier issue.  New issue DPD200247184 created for this one.

0 Kudos
thomas_boehme
New Contributor II
647 Views

Steve, thanks for keeping me informed and creating the new issue.

BR, Thomas

 

 

0 Kudos
Steven_L_Intel1
Employee
647 Views

This uncovered multiple problems, which required fixes in the compiler and run-time library. It looks as if those will get in for the October update.

0 Kudos
Reply