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

Bug Report: Incorrect Call to Elemental Final Subroutine on Deallocating Zero-Sized Array

gzengm
Novice
469 Views

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.

1 Reply
Xiaoping_D_Intel
Employee
304 Views

The problem can be reproduced with oneAPI 2024.0. I also found it no longer happens since oneAPI 2024.1.


0 Kudos
Reply