Last active
March 15, 2019 14:05
-
-
Save pelson/73710120d5e7ede9318bbf56fb52c52a to your computer and use it in GitHub Desktop.
Demonstration of Intel Fortran compiler issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gfortran -g main.f90 -fbacktrace -O0 && ./a.out | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ifort main.f90 \ | |
-traceback -warn interface \ | |
-o a.intel.out && ./a.intel.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module container_example | |
type containable_base_type | |
character(80) :: name | |
end type containable_base_type | |
type, public :: container_type | |
class(containable_base_type), pointer :: payload => null() | |
contains | |
final :: container_destructor | |
end type container_type | |
interface container_type | |
module procedure container_constructor | |
end interface container_type | |
contains | |
function container_constructor(child) result(self) | |
type(container_type) :: self | |
class(containable_base_type), intent (in) :: child | |
print*, "Construct container" | |
allocate(self%payload, source=child) | |
end function container_constructor | |
subroutine container_destructor(self) | |
type (container_type), intent(inout) :: self | |
print*, "Destruct container" | |
if (associated(self%payload)) then | |
! BOOM! with the intel compiler second time around. | |
deallocate(self%payload) | |
end if | |
end subroutine container_destructor | |
end module container_example | |
program main | |
use container_example | |
type(container_type) :: holder | |
holder = container_type(containable_base_type('example 1')) | |
print*, holder%payload%name | |
holder = container_type(containable_base_type('example 2')) | |
print*, holder%payload%name | |
end program main |
This is essentially ifort copying pointers rather than copying the data being pointed to as its default assignment behaviour. A shared pointer concept would be reasonably easy to implement in F2003 I believe.
It seems that associated
is not safe in the ifort implementation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Solution: implement assignment such as