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

Segmentation fault with derived type assignment and generic binding

ronan23
Beginner
645 Views
Hello,
Here is an example of what causes a segmentation fault in my F2003 code :
[fortran]module m implicit none ! Type definition type :: my_type real, allocatable, dimension(:) :: Tab ! Allocatable array (LINE 1) real :: T ! Followed by something else (LINE 2) contains generic :: init => init1, init2 ! With a generic method (LINE 3) procedure :: init1 procedure :: init2 end type contains !------------------------------------ subroutine init1(self) class(my_type) :: self end subroutine init1 !------------------------------------ subroutine init2(self, n) class(my_type) :: self integer :: n end subroutine init2 !------------------------------------ end module m program test use m implicit none type(my_type) :: a, b ! Fill first object a%T = 2.0 allocate(a%Tab(10)) a%Tab(:) = 0.0 ! assignment of 2nd object b = a ! This causes segmentation fault end program test[/fortran]
Commenting "LINE 1", "LINE 2" or "LINE 3" and the corresponding line in the program where values are given to components of object 'a' makes the segmentation fault disappear. The combination of allocatable component and generic binding then seems to be the reason.
I compiled with the option '-assumerealloc_lhs' or '-standard-semantics' but this did not fix it.
My compilier version is :
ifort (IFORT) 12.1.0 20110811
Thanks.
0 Kudos
3 Replies
Steven_L_Intel1
Employee
645 Views
This looks familiar - I think it's a bug we have fixed for a release in September. I will check when I get into the office on Monday.
0 Kudos
Steven_L_Intel1
Employee
645 Views
Yes, this works in the September release version.
0 Kudos
ronan23
Beginner
645 Views
Thanks, I'll make sure to check out this version when it is released.
In the meantime, I found out that putting allocatable components at the end of the derived type declaration enables to avoid the bug.
0 Kudos
Reply