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

ALLOCATE(...SOURCE=xxx) and OPTIONAL

IanH
Honored Contributor II
455 Views

If I use an optional dummy as the SOURCE expression in an allocate statement I get some runtime grief.

MODULE ma
  IMPLICIT NONE
  
  TYPE :: ta
  END TYPE ta
CONTAINS
  SUBROUTINE proc(arg)
    TYPE(ta), INTENT(IN), OPTIONAL :: arg
    TYPE(ta), ALLOCATABLE :: x
    IF (PRESENT(arg)) THEN
      ALLOCATE(x, SOURCE=arg)
    END IF
  END SUBROUTINE proc
END MODULE ma

PROGRAM p
  USE ma
  IMPLICIT NONE
  TYPE(ta) :: y
  CALL proc(y)
END PROGRAM p
>ifort /check:all /warn:all /standard-semantics "2016-07-20 optional-nonpolymorphic.f90" && "2016-07-20 optional-nonpolymorphic.exe"
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.3.207 Build 20160415
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

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

"-out:2016-07-20 optional-nonpolymorphic.exe"
-subsystem:console
"2016-07-20 optional-nonpolymorphic.obj"
forrtl: severe (157): Program Exception - access violation
Image              PC                Routine            Line        Source
2016-07-20 option  00007FF7C79E1159  Unknown               Unknown  Unknown
2016-07-20 option  00007FF7C79E1203  Unknown               Unknown  Unknown
2016-07-20 option  00007FF7C7A0D8AE  Unknown               Unknown  Unknown
2016-07-20 option  00007FF7C7A0E199  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFE283B8102  Unknown               Unknown  Unknown
ntdll.dll          00007FFE28C2C5B4  Unknown               Unknown  Unknown

 

A variant, with a polymorphic argument fed by a structure constructor, causes a spurious runtime error with the current beta.

MODULE ma
  IMPLICIT NONE
  
  TYPE :: ta
  END TYPE ta
CONTAINS
  SUBROUTINE proc(arg)
    CLASS(ta), INTENT(IN), OPTIONAL :: arg
    CLASS(ta), ALLOCATABLE :: x
    IF (PRESENT(arg)) THEN
      ALLOCATE(x, SOURCE=arg)
    END IF
  END SUBROUTINE proc
END MODULE ma

MODULE mb
  USE ma
  IMPLICIT NONE
  
  TYPE, EXTENDS(ta) :: tb
  END TYPE tb
END MODULE mb

PROGRAM p
  USE ma
  USE mb
  IMPLICIT NONE
  CALL proc(tb())
END PROGRAM p

 

>ifort /check:all /warn:all /standard-semantics "2016-07-20 optional-polymorphic.f90" && "2016-07-20 optional-polymorphic.exe"
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0 Beta Build 20160517
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

ifort: NOTE: The Beta evaluation period for this product ends on 7-oct-2016 UTC.
Microsoft (R) Incremental Linker Version 14.00.24210.0
Copyright (C) Microsoft Corporation.  All rights reserved.

"-out:2016-07-20 optional-polymorphic.exe"
-subsystem:console
"2016-07-20 optional-polymorphic.obj"
forrtl: severe (190): for allocate(source=), source needs to be allocated
Image              PC                Routine            Line        Source
2016-07-20 option  00007FF72F7D26D0  Unknown               Unknown  Unknown
2016-07-20 option  00007FF72F7D1169  Unknown               Unknown  Unknown
2016-07-20 option  00007FF72F7D139C  Unknown               Unknown  Unknown
2016-07-20 option  00007FF72F80044E  Unknown               Unknown  Unknown
2016-07-20 option  00007FF72F800D79  Unknown               Unknown  Unknown
KERNEL32.DLL       00007FFE283B8102  Unknown               Unknown  Unknown
ntdll.dll          00007FFE28C2C5B4  Unknown               Unknown  Unknown

 

0 Kudos
1 Reply
Steven_L_Intel1
Employee
455 Views

I don't think the OPTIONAL is part of this. The compiler is trying to copy data from the empty type, which it shouldn't. If the type has a component it works. Issue ID is DPD200412834. We have another open issue regarding assignment of empty types which I think is related.

0 Kudos
Reply