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

Problem with finalizer

Li_Dong
Beginner
851 Views
Dear all,
I want to use the final bounding to clean a linked list, the simple example is:
[fortran]module TypeDef

    implicit none

    type A
        integer :: id = -1
        type(A), pointer :: next => null()
    contains
        final :: A_clean
    end type A

contains

    subroutine A_clean(this)
        type(A), intent(inout) :: this

        print *, "Clean element", this%id
        if (associated(this%next)) deallocate(this%next)

    end subroutine A_clean

end module TypeDef

program TBPFinal

    use TypeDef

    implicit none

    type(A), pointer :: head

    allocate(head)
    head%id = 1
    allocate(head%next)
    head%next%id = 2
    deallocate(head)

end program TBPFinal[/fortran]
When I compile it with ifort 12, it complains:
ifort: error #10106: Fatal error in /opt/intel/composerxe-2011.0.085/bin/ia32/fortcom, terminated by segmentation violation
compilation aborted for TBPFinal.f90 (code 1)
Any idea? I also changed the attribute of "head" from "pointer" to "allocatable", since the document says:

A data entity is finalizable if it is of a finalizable type and is not a pointer.

dongli
0 Kudos
4 Replies
Xiaoping_D_Intel
Employee
851 Views
It is a compiler bug. I will submit a bug report and keep you posted.

Thanks,
Xiaoping Duan
Intel Customer Support
0 Kudos
jahern
Beginner
851 Views
I just encountered a similar problem when creating a linked list type - possibly the same. The reduced code is:
[fortran]MODULE err
   IMPLICIT NONE
   TYPE Object
      TYPE(Object), POINTER :: next => NULL()
   CONTAINS
      FINAL :: Finalize_Object
   END TYPE Object
CONTAINS
   SUBROUTINE Finalize_Object(self)
      TYPE(Object), INTENT(INOUT) :: self
      DEALLOCATE(self%next)
   END SUBROUTINE Finalize_Object
END MODULE err[/fortran]
The error I obtained was nearly the same, but with a different platform and version:
[plain]fort: error #10106: Fatal error in /opt/intel/composerxe-2011.1.107/bin/intel64/fortcom, terminated by segmentation violation
compilation aborted for error.F90 (code 1)[/plain]
This error occurred when compiling the above on Fedora 14 x64 with ifort12.0.0 20101116 froml_fcompxe_intel64_2011.1.107. Hopefully this will help with the diagnosis!
Regards,
Jared Ahern
0 Kudos
pbkenned1
Employee
851 Views
Both of the examples in this thread are resolved in Composer XE update #6 (aka 12.1 compiler). The packages containing the fixes are:

l_fcompxe_2011.6.233

m_fcompxe_2011.6.038

w_fcompxe_2011.6.233

The first example produces:

>ifort U79148.f90

Intel Visual Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.0.233 Build 2011081

-out:U79148.exe

>U79148.exe

Clean element 1

Clean element 2

Patrick Kennedy

0 Kudos
jimdempseyatthecove
Honored Contributor III
851 Views
It should be noted that your finalize routine could be potentially called explicitly, say to truncate your list at some point, therefor consider adding a nullify for the line pointer.

Jim Dempsey
0 Kudos
Reply