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

Allocatable function result should not have allocatable attribute

Harald1
New Contributor II
930 Views

Hello,

the following code is accepted by Intel but rejected by NAG:

program main
  integer, allocatable :: p
  p = f()
  print *, allocated(p)
  print *, is_allocated(p)
  print *, is_allocated(f())    ! Invalid per F2018 8.5.3 Note 1

contains
  function f()
    integer, allocatable :: f
    allocate (f, source=42)
  end function

  logical function is_allocated(p)
    integer, allocatable :: p

    is_allocated = allocated(p)
  end function
end program

NAG prints:

NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101
Error: pr109500.f90, line 6: Expected an ALLOCATABLE variable for argument P (no. 1) of IS_ALLOCATED
[NAG Fortran Compiler error termination, 1 error]

Indeed Fortran 2018, 8.5.1, Note 1 says:

Only variables and components can have the ALLOCATABLE attribute. The result of referencing a func-
tion whose result variable has the ALLOCATABLE attribute is a value that does not itself have the
ALLOCATABLE attribute.

 At least in standard conformance mode Intel should diagnose this, but ifort silently accepts it, and ifx crashes with:

pr109500.f90(6): error #5623: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
  print *, is_allocated(f())    ! Invalid per F2018 8.5.3 Note 1
--^
compilation aborted for pr109500.f90 (code 3)

(traceback elided).

 

1 Solution
Barbara_P_Intel
Employee
812 Views

Bug filed for the missing error message, CMPLRLLVM-46937, with both reproducers. I'll let you know when it's fixed.

 

 

View solution in original post

0 Kudos
5 Replies
FortranFan
Honored Contributor II
903 Views

Intel team,

Perhaps you will consider the following variant also toward the bug incident report.  Note the lines marked A, B, and C.  A conforming processor shall detect and report noncompliance with each of these 3 cases, but IFORT fails to do so with C.  As OP stated, IFX encounters an ICE with C.

 

   !call sub( 0 )    !<-- A
   !call sub( f1() ) !<-- B
   call sub( f2() )  !<-- C
contains
   subroutine sub( a )
      integer, allocatable :: a
   end subroutine
   function f1() result(r)
      integer :: r
      r = 42
   end function
   function f2() result(r)
      integer, allocatable :: r
      r = 42
   end function
end 
C:\temp>ifx /c /free /standard-semantics p.f
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.1.0 Build 20230320
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

 #0 0x00007ff6012d075a (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x30075a)
 #1 0x00007ff6012d072a (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x30072a)
 #2 0x00007ff6011f66d4 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x2266d4)
 #3 0x00007ff6011c9c3a (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x1f9c3a)
 #4 0x00007ff601210d48 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x240d48)
 #5 0x00007ff6012563d8 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x2863d8)
 #6 0x00007ff601256a30 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x286a30)
 #7 0x00007ff601255480 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x285480)
 #8 0x00007ff60124bbfc (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x27bbfc)
 #9 0x00007ff601249de9 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x279de9)
#10 0x00007ff6012491bc (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x2791bc)
#11 0x00007ff60132206f (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x35206f)
#12 0x00007ff60132265c (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x35265c)
#13 0x00007ff601324b66 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x354b66)
#14 0x00007ff60132206f (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x35206f)
#15 0x00007ff60131effd (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x34effd)
#16 0x00007ff60132206f (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x35206f)
#17 0x00007ff60119f90a (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x1cf90a)
#18 0x00007ff60119f34a (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x1cf34a)
#19 0x00007ff60138c31e (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x3bc31e)
#20 0x00007ff6037f6060 (C:\PROGRA~2\Intel\oneAPI\compiler\latest\windows\bin-llvm\xfortcom.exe+0x2826060)
#21 0x00007ff84f307614 (C:\WINDOWS\System32\KERNEL32.DLL+0x17614)
#22 0x00007ff84f5426a1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526a1)

p.f(3): error #5623: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
   call sub( f2() )  !<-- C
---^
compilation aborted for p.f (code 3)

C:\temp>ifort /c /free /standard-semantics p.f
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.9.0 Build 20230302_000000
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.


C:\temp>

 

Barbara_P_Intel
Employee
818 Views

The ICE with ifx is melted (gone) for both reproducers in the next release.

Checking on the missing error message...

 

0 Kudos
Barbara_P_Intel
Employee
813 Views

Bug filed for the missing error message, CMPLRLLVM-46937, with both reproducers. I'll let you know when it's fixed.

 

 

0 Kudos
Barbara_P_Intel
Employee
467 Views

@Harald1 and @FortranFan, when you install the compilers that were released this week you will find error messages for the invalid code in both reproducers.

Please check out 2024.0!


0 Kudos
Harald1
New Contributor II
456 Views

Confirmed.  I now get appropriate error messages for the testcase.

Thanks!

 

0 Kudos
Reply