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

OOP related bug in ifx

GreenScreen
Beginner
411 Views

The following code is a minimal reproducer of a bug in ifx's (and ifort's) support of Fortran's OOP features that has been bugging me for ages. This test code should simply execute, and exit gracefully (and it does indeed so using LLVM's Flang compiler, version 19.0.0).

module base_module

   type, abstract :: BaseType
   contains
      procedure(method), deferred  :: method
   end type BaseType

   abstract interface
      subroutine method(self)
         import
         class(BaseType), intent(in) :: self
      end subroutine method
   end interface

end module base_module

module ext_module
   
   use base_module, only: BaseType

   type, extends(BaseType) :: ExtType
      real(8), allocatable :: y(:,:)
   contains
      procedure :: method
   end type ExtType

contains

   subroutine method(self)
      class(ExtType), intent(in) :: self      
      real(8), allocatable :: y(:,:)
      y = self%y
   end subroutine method

end module ext_module

program main

   use base_module, only: BaseType
   use ext_module,  only: ExtType

   class(BaseType), allocatable :: arr(:)

   arr = make_arr()   
   call arr(1)%method()
     
contains

   function make_arr() result(arr)
      class(BaseType), allocatable :: arr(:)
      real :: y(32768,2)
      allocate(ExtType :: arr(1))
      arr = ExtType(y)
   end function make_arr

end program main

When compiled and run with ifx (Version 2025.0.4 Build 20241205), the result is a segmentation fault, with the following trace-back:

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
libc.so.6          0000152670033520  Unknown               Unknown  Unknown
main.ifx           00000000004655E0  __intel_ssse3_mem     Unknown  Unknown
main.ifx           000000000040547E  Unknown               Unknown  Unknown
main.ifx           0000000000405A56  Unknown               Unknown  Unknown
main.ifx           000000000040516D  Unknown               Unknown  Unknown
libc.so.6          000015267001AD90  Unknown               Unknown  Unknown
libc.so.6          000015267001AE40  __libc_start_main     Unknown  Unknown
main.ifx           0000000000405085  Unknown               Unknown  Unknown

The problem seems to be somehow connected to the fact that the procedure make_arr is coded as a function. When this procedure is transformed into a subroutine, the segfault vanishes.

0 Kudos
5 Replies
TobiasK
Moderator
286 Views

@GreenScreen


Can you give more details on how you compile the code? On Linux with -O0 I don't see an issue.


0 Kudos
GreenScreen
Beginner
279 Views

ifx main.f90 -o main.ifx

 

I am using ifx Version 2025.0.4 Build 20241205 on Linux Mint 21.1 Vera.

0 Kudos
GreenScreen
Beginner
278 Views

I've tried the -O0 option for compilation, but it doesn't change anything. It still segfaults.

(Always assuming that the code that I've posted above is stored in a single file, main.f90.)

0 Kudos
TobiasK
Moderator
238 Views

Ok, while playing around with the code I changed the second dimension of y to 1 which triggers the segfault only if -heap-arrays are used.

With your original size it fails regardless of heap-arrays.

I escalated it to our developers.


0 Kudos
GreenScreen
Beginner
226 Views
0 Kudos
Reply