- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Description: There is a bug in the ifx and ifort compilers when deallocating a zero-sized array whose parent type has an elemental final subroutine. The parent type's elemental final subroutine is erroneously called during the deallocation process, which should not occur.
Code to Reproduce: The following code snippet demonstrates the issue:
module types_module
implicit none
type :: parent_type
integer, pointer :: int_ptr => null()
contains
final :: parent_elemental_final
end type parent_type
type, extends(parent_type) :: child_type
end type child_type
contains
elemental subroutine parent_elemental_final(this)
implicit none
type(parent_type), intent(inout) :: this
if (associated(this%int_ptr)) deallocate(this%int_ptr)
end subroutine parent_elemental_final
end module types_module
program BugZeroSizeArray
use types_module
implicit none
type(child_type), allocatable :: child(:)
allocate (child(0))
deallocate (child)
end program BugZeroSizeArray
Observed Behavior: When the above code is executed, the elemental final subroutine parent_elemental_final is called during the deallocation of the zero-sized array child. This behavior is incorrect, as the final subroutine should not be invoked for zero-sized arrays.
Expected Behavior: The elemental final subroutine should not be called when deallocating a zero-sized array.
Tested Compiler Versions:
- ifx: Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.2 Build 20231213
- ifort: Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.11.1 Build 20231117_000000
Impact: This bug was discovered while using custom shared pointer types, and it may lead to unintended deallocation and associated memory issues.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem can be reproduced with oneAPI 2024.0. I also found it no longer happens since oneAPI 2024.1.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page