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

compiler bug - array of abstract class

Ernst_A__Meese
Beginner
853 Views

The code below compiles well with ifort (IFORT) 15.0.0 20140723 under Linux, however, it terminates abruptly when accessing an array element.  There is no error message or stack traceback even when using

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

to compile.

----8<--------8<--------8<--------8<--------8<--------8<--------8<----

MODULE class_IFoo
  IMPLICIT NONE
  PRIVATE

  TYPE, ABSTRACT, PUBLIC :: IFoo
   CONTAINS
     PROCEDURE(getBarI), DEFERRED, PUBLIC :: getBar
     PROCEDURE(setBarI), DEFERRED, PUBLIC :: setBar
  END TYPE IFoo
  ABSTRACT INTERFACE
     INTEGER FUNCTION getBarI( this ) RESULT( bar )
       IMPORT :: IFoo
       CLASS(IFoo), INTENT(in) :: this
     END FUNCTION getBarI
     SUBROUTINE setBarI( this, bar )
       IMPORT :: IFoo
       CLASS(IFoo), INTENT(inout) :: this
       INTEGER,     INTENT(in)    :: bar
     END SUBROUTINE setBarI
  END INTERFACE
END MODULE class_IFoo
MODULE class_TFoo
  USE class_IFoo, ONLY : IFoo
  IMPLICIT NONE
  PRIVATE

  TYPE, EXTENDS(IFoo), PUBLIC :: TFoo
     INTEGER :: bar
   CONTAINS
     PROCEDURE, PUBLIC :: getBar
     PROCEDURE, PUBLIC :: setBar
  END TYPE TFoo

CONTAINS
  INTEGER FUNCTION getBar( this ) RESULT(bar)
    CLASS(TFoo), INTENT(in) :: this
    bar = this % bar
  END FUNCTION getBar
  SUBROUTINE SetBar( this, bar)
    CLASS(TFoo), INTENT(inout) :: this
    INTEGER,     INTENT(in)    :: bar
    this % bar = bar
  END SUBROUTINE SetBar
END MODULE class_TFoo
PROGRAM test_array_of_abstract
  USE class_IFoo, ONLY : IFoo
  USE class_TFoo, ONLY : TFoo
  IMPLICIT NONE
  INTEGER,     PARAMETER   :: N = 2
  INTEGER                  :: i, bar
  CLASS(IFoo), ALLOCATABLE :: foo(:)
  CLASS(IFoo), ALLOCATABLE :: fooSource
 
  ALLOCATE( TFoo :: fooSource )
  CALL fooSource % setBar( 13 )
  PRINT '(A,I2)', 'The bar value of the source is set to ', fooSource % getBar()

  ALLOCATE( foo, SOURCE = SPREAD( fooSource, 1, N ) )

  DO i = 1, N
     PRINT '(A,I2)', 'Getting bar from foo#', i
     bar = foo(i)%getBar()                           !  This line terminates the code with no message
     PRINT '(A,I2)', 'Found bar to be', bar
  END DO

END PROGRAM test_array_of_abstract

 

0 Kudos
4 Replies
FortranFan
Honored Contributor III
853 Views

A good one.

It'll be interesting to learn about this from Intel folks.  The problem appears with the statement [fortran]ALLOCATE( foo, SOURCE = SPREAD( fooSource, 1, N ) )[/fortran] specifically the use of SPREAD intrinsic since the following executes [fortran]ALLOCATE( foo(N), SOURCE = fooSource ) !.. works ok[/fortran].

0 Kudos
pbkenned1
Employee
853 Views

Looks like an ifort bug getting the return type of SPREAD( fooSource, 1, N ) correct, ie, a rank one array of extent N, each element a copy of fooSource.  Just as FortranFan noted, that should be equivalent to ALLOCATE( foo(N), SOURCE = fooSource).

I'll report this to the developers.

Patrick

0 Kudos
pbkenned1
Employee
853 Views

Reported to the developers, internal tracking ID DPD200363043.  I'll let you know what they have to say.

Patrick

0 Kudos
pbkenned1
Employee
853 Views

This is resolved in Composer XE 2015 update #2, so I'm closing this ticket now.  This was complicated to fix, numerous tweaks were needed to make spread work correctly with polymorphic vars.
 

Patrick

[U535070]$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.2.164 Build 20150121
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

[U535070]$ ifort U535070.f90 -o U535070.f90.x
[U535070]$ ./U535070.f90.x
The bar value of the source is set to 13
Getting bar from foo# 1
Found bar to be13
Getting bar from foo# 2
Found bar to be13
[U535070]$

0 Kudos
Reply