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

Possible Compiler Bug - segfault

Ernst_A__Meese
Beginner
411 Views

The code below crashes with a segmentation fault when compiled with ifort (IFORT) 15.0.0 20140723 under Linux using the command

ifort -o testing -stand f08 -check bounds -nologo -fpe:0 -debug full -O0 -warn all -traceback -dbglibs test3.f90

Not compiling with -debug full makes the code run as expected.

MODULE class_base
  IMPLICIT NONE
  PRIVATE

  TYPE, PUBLIC :: TBase
     REAL, ALLOCATABLE :: foo(:)
   CONTAINS
     PROCEDURE, PUBLIC :: init
     PROCEDURE, PUBLIC :: get
  END TYPE TBase

CONTAINS
  SUBROUTINE init( this )
    CLASS(TBase), INTENT(out) :: this
    ALLOCATE( this % foo, SOURCE = [2.71, 3.14] )
  END SUBROUTINE init

  FUNCTION get( this ) RESULT( foo )
    CLASS(TBase), INTENT(in)  :: this
    REAL,         ALLOCATABLE :: foo(:)
    ALLOCATE( foo, SOURCE=this % foo )
  END FUNCTION get
END MODULE class_base

MODULE class_container
  USE class_Base, ONLY : TBase
  IMPLICIT NONE
  PRIVATE

  ! In this trivial example, we could have used TYPE(TBase), in which case segfault is
  ! not caused.  However, in the real application, we need a dynamic class.
  TYPE, PUBLIC :: TContainer
     CLASS(TBase), ALLOCATABLE :: bar
   CONTAINS
     PROCEDURE :: init
  END type TContainer

CONTAINS
  SUBROUTINE init( this )
    CLASS(TContainer), INTENT(out) :: this
    ALLOCATE( this % bar )
    CALL this % bar % init()
  END SUBROUTINE init
END MODULE class_container

MODULE class_Containerlist
  USE class_Container, ONLY : TContainer
  IMPLICIT NONE
  PRIVATE

  TYPE, PUBLIC :: TContainerlist
     CLASS(TContainer),  ALLOCATABLE :: container(:)
   CONTAINS
     PROCEDURE :: segfaultingRoutine
  END TYPE TContainerlist

CONTAINS
  SUBROUTINE segfaultingRoutine( this )
    CLASS(TContainerlist), INTENT(out) :: this
    INTEGER :: i, j
    REAL    :: foo(2)

    ALLOCATE( this % container( 3 ) )

    DO i = 1, 3
       CALL this%container(i)%init()
       ! Checking if all is well will all already created elements
       DO j = 1, i
          foo = this%container(j)%bar%get()
          print '(I3,1P,2E12.4)', j, foo
       END DO
    END DO

    !  Doing this loop works well
    DO j = 1, 3
       foo = this%container(j)%bar%get()
       print '(I3,1P,2E12.4)', j, foo
    END DO

    foo = this%container(1)%bar%get(); print *, '** 1 ** ', foo ! This one goes through
    foo = this%container(2)%bar%get(); print *, '** 2 ** ', foo ! This one failes
    foo = this%container(3)%bar%get(); print *, '** 3 ** ', foo

  END SUBROUTINE segfaultingRoutine

END MODULE class_Containerlist

PROGRAM compiler_error_segmentation_fault
  USE class_Containerlist,     ONLY : TContainerlist
  IMPLICIT NONE
  TYPE(TContainerlist)     :: cl

  CALL cl % segfaultingRoutine()

END PROGRAM compiler_error_segmentation_fault

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
411 Views

Thanks - I can reproduce this and am investigating.

0 Kudos
Steven_L_Intel1
Employee
411 Views

Escalated as issue DPD200362917.

0 Kudos
Reply