Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26758 Discussions

Bug(?) in sourced allocation when type hierachy contains generic assignment

may_ka
Beginner
129 Views

Hi,

the code:

Module testmod
  Type :: root_type
    integer, allocatable :: a
  contains
    Generic, Public :: Assignment(=) => Copy
    Procedure, Pass(this) :: Copy => SubCopy
  End type root_type
  Type, extends(root_type) :: child_type
  End type child_type
contains
  Subroutine SubCopy(other,this)
    Class(root_type), Intent(In) :: this
    Class(root_type), Intent(InOut) :: other
    Allocate(other%a,source=this%a)
  end Subroutine SubCopy
End Module testmod
Program Test
  Use testmod, only: child_type
  Type(child_type), allocatable :: x,y
  allocate(x)
  allocate(y,source=x)
end Program Test

compiles with ifort 17.05 to 18.01 and with gfortran 7.2, but the ifort exec yields a seg fault at run time:

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              000000000040396D  Unknown               Unknown  Unknown
libpthread-2.26.s  000014D0F3566DA0  Unknown               Unknown  Unknown
a.out              0000000000402A8E  Unknown               Unknown  Unknown
a.out              00000000004029DE  Unknown               Unknown  Unknown
libc-2.26.so       000014D0F31BDF4A  __libc_start_main     Unknown  Unknown
a.out              00000000004028EA  Unknown               Unknown  Unknown

workaround is to either use "root_type" directly, or to comment the generic assignment. I am almost certain that this is a bug, but maybe others can confirm or tell me what I did wrong.

Cheers

0 Kudos
3 Replies
FortranFan
Honored Contributor II
129 Views

The standard specifies for the ALLOCATE statement, "If source-expr is allocatable, it shall be allocated." which is not the case in the code you show: in your SubCopy procedure, the instructions need to take into account whether this%a is allocated.

may_ka
Beginner
129 Views

You mean that one would need something like:

if(allocated(this%a) then
  Allocate(other%a,source=this%a)
End if

!?

That also seems to solve the seg fault.

THANK YOU.

FortranFan
Honored Contributor II
129 Views

may.ka wrote:

You mean that one would need something like:

if(allocated(this%a) then
  Allocate(other%a,source=this%a)
End if

!? ..

Yep.  

Reply