- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
There seems to be a bug in final procedure if the procedure is elemental. The following example (module and program) illustrate the bug:
[fortran]module RaggedArrayModule implicit none private type, public :: RaggedArrayInteger integer, dimension(:), allocatable :: Value contains procedure, public, pass :: Initialize final :: Finalize end type RaggedArrayInteger contains subroutine Initialize(A, nValues) class(RaggedArrayInteger), intent(inout) :: A integer, intent(in) :: nValues allocate (A%Value(nValues)) end subroutine Initialize elemental subroutine Finalize(A) type(RaggedArrayInteger), intent(inout) :: A if (allocated(A%Value)) deallocate(A%Value) end subroutine Finalize end module RaggedArrayModule program RaggedArray_Test use RaggedArrayModule type(RaggedArrayInteger), dimension(:), allocatable :: MyArray !-- This works as expected allocate (MyArray(1)) call MyArray(1)%Initialize(10) deallocate(MyArray) !-- Allocating array with size zero is legal, but produce ! segfault in deallocation when final procedure is elemental allocate(MyArray(0)) deallocate(MyArray) end program RaggedArray_Test [/fortran]
In other words, I think the issue is because when the size of MyArray is allocated to zero, the deallocation triggers the elemental final procedure "Finalize()" and try to access its first element when the actual size is zero. I believe this is a behavior is a bug.
There seems to be a bug in final procedure if the procedure is elemental. The following example (module and program) illustrate the bug:
[fortran]module RaggedArrayModule implicit none private type, public :: RaggedArrayInteger integer, dimension(:), allocatable :: Value contains procedure, public, pass :: Initialize final :: Finalize end type RaggedArrayInteger contains subroutine Initialize(A, nValues) class(RaggedArrayInteger), intent(inout) :: A integer, intent(in) :: nValues allocate (A%Value(nValues)) end subroutine Initialize elemental subroutine Finalize(A) type(RaggedArrayInteger), intent(inout) :: A if (allocated(A%Value)) deallocate(A%Value) end subroutine Finalize end module RaggedArrayModule program RaggedArray_Test use RaggedArrayModule type(RaggedArrayInteger), dimension(:), allocatable :: MyArray !-- This works as expected allocate (MyArray(1)) call MyArray(1)%Initialize(10) deallocate(MyArray) !-- Allocating array with size zero is legal, but produce ! segfault in deallocation when final procedure is elemental allocate(MyArray(0)) deallocate(MyArray) end program RaggedArray_Test [/fortran]
In other words, I think the issue is because when the size of MyArray is allocated to zero, the deallocation triggers the elemental final procedure "Finalize()" and try to access its first element when the actual size is zero. I believe this is a behavior is a bug.
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I forgot to mention the compiler version I'm using:
$ ifort -V
Intel Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1 Build 20111128
Copyright (C) 1985-2011 Intel Corporation. All rights reserved
Thanks.
RDB
$ ifort -V
Intel Fortran Intel 64 Compiler XE for applications running on Intel 64, Version 12.1 Build 20111128
Copyright (C) 1985-2011 Intel Corporation. All rights reserved
Thanks.
RDB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is useless to deallocate an allocatable component in a final procedure. Remember that allocatable components are just "smart pointers" and are made to deallocate the memory they refer to when they go out of scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Interesting. We'll take a look at this.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page