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

Default initialization of component of polymorphic object causes access violation, strong headache and loss of weekend

IanH
Honored Contributor III
546 Views
The following after compiling with 12.1.1 explodes at runtime with an access violation that seems unwarranted. 12.0.5 doesn't appear to have an issue.

[fortran]MODULE SomeTypesAndAFactoryForThoseTypes  
  IMPLICIT NONE
  PRIVATE
  !----
  TYPE, ABSTRACT, PUBLIC :: ParentType
    INTEGER :: a = 1        ! Note default initialization.
  CONTAINS
    PROCEDURE(parent_Proc), DEFERRED :: Proc
  END TYPE ParentType
  
  ABSTRACT INTERFACE
    SUBROUTINE parent_Proc(obj)
      IMPORT :: ParentType
      IMPLICIT NONE
      CLASS(ParentType), INTENT(OUT) :: obj
    END SUBROUTINE parent_Proc
  END INTERFACE
  
  TYPE, PUBLIC, EXTENDS(ParentType) :: OneType
    INTEGER :: b
  CONTAINS
    PROCEDURE :: Proc => one_Proc
  END TYPE OneType
  
  TYPE, PUBLIC, EXTENDS(ParentType) :: TwoType
    REAL :: c
  CONTAINS
    PROCEDURE :: Proc => two_Proc
  END TYPE TwoType

  PUBLIC :: Factory  
  INTERFACE Factory
    MODULE PROCEDURE Factory_
  END INTERFACE Factory
CONTAINS
  SUBROUTINE Factory_(str, obj)
    CHARACTER(*), INTENT(IN) :: str
    CLASS(ParentType), INTENT(OUT), ALLOCATABLE :: obj
    !****
    SELECT CASE (str)
    CASE ('one')
      ALLOCATE(OneType:: obj)
    CASE ('two')
      ALLOCATE(TwoType :: obj)
    CASE DEFAULT
      ! Just leave unallocated
    END SELECT
  END SUBROUTINE Factory_
  
  SUBROUTINE one_Proc(obj)
    CLASS(OneType), INTENT(OUT) :: obj
    !****
    obj%a = 1
    obj%b = 2
  END SUBROUTINE one_Proc
  
  SUBROUTINE two_Proc(obj)
    CLASS(TwoType), INTENT(OUT) :: obj
    !****
    obj%a = 10
    obj%c = 30.0
  END SUBROUTINE two_Proc
END MODULE SomeTypesAndAFactoryForThoseTypes

PROGRAM DearIntelDevelopersForTwelvePointOneYouOweMeACaseOfBeer
  USE SomeTypesAndAFactoryForThoseTypes
  IMPLICIT NONE
  CLASS(ParentType), ALLOCATABLE :: obj
  !****
  CALL Factory('one', obj)
  IF (.NOT. ALLOCATED(obj)) STOP
  
  CALL obj%Proc
END PROGRAM DearIntelDevelopersForTwelvePointOneYouOweMeACaseOfBeer
[/fortran]

[plain]>ifort /check:all /warn:all /standard-semantics /traceback ItsFridayAndImThirsty.f90
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.1.1.258 Build 20111011
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:ItsFridayAndImThirsty.exe
-subsystem:console
-incremental:no
ItsFridayAndImThirsty.obj

>ItsFridayAndImThirsty.exe
forrtl: severe (157): Program Exception - access violation
Image              PC        Routine            Line        Source
ItsFridayAndImThi  008F13E5  _SOMETYPESANDAFAC          55  ItsFridayAndImThirsty.f90
ItsFridayAndImThi  008F10DA  _MAIN__                    73  ItsFridayAndImThirsty.f90
ItsFridayAndImThi  0091F923  Unknown               Unknown  Unknown
ItsFridayAndImThi  0090AF1D  Unknown               Unknown  Unknown
kernel32.dll       761AD309  Unknown               Unknown  Unknown
ntdll.dll          76F716C3  Unknown               Unknown  Unknown
ntdll.dll          76F71696  Unknown               Unknown  Unknown[/plain]
0 Kudos
4 Replies
Steven_L_Intel1
Employee
546 Views
Thanks - I have passed this along to the developers. The issue ID is DPD200176585.
0 Kudos
Steven_L_Intel1
Employee
546 Views
Unfortunately, fixing this properly required a complicated change that we don't want to put into a minor update. It is fixed for the next major release.
0 Kudos
IanH
Honored Contributor III
546 Views
Thanks. I'm still thirsty, but have moved off beer and onto wine. Any thoughts as to when I might be able to download the next major release crack the screw top on the semillon that's hiding up the back of the fridge?
0 Kudos
Steven_L_Intel1
Employee
546 Views
Your wine will need to age some more months, but you'll be able to enjoy it this year.
0 Kudos
Reply