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

ICE with parameterized derived type as function output

WileyOne
Novice
1,326 Views

Compiler: ifx (IFX) 2025.2.0

OS: Rocky Linux 8.10 (Green Obsidian)

 

I originally found this issue on 2024.2.0 and verified that it is still crashing with the latest compiler version.

module Ice5623_Example

    type :: SomeSystem(nStates)
        integer, len :: nStates
    end type

    type :: SomeClass
        type(SomeSystem(:)), allocatable :: model
    end type

    contains

    function constructor(nStates) result(this)
        integer                   :: nStates
        type(SomeSystem(nStates)) :: this
    end function

    subroutine configure(this, integer1, integer2)
        type(SomeClass) :: this
        integer         :: integer1, integer2

        this%model = constructor(integer1*integer2)
    end subroutine

end module

This code produces the following error:

Terminal.png

0 Kudos
4 Replies
Ron_Green
Moderator
1,296 Views

A compiler should never ICE.   But in this case at least it did emit a warning message to alert us that the code was invalid:

Ice5623_Example.f90(13): warning #6178: The return value of this FUNCTION has not been defined.   [THIS]
    function constructor(nStates) result(this)
-----------------------------------------^

After which the compiler is still attempting to compile invalid code and hits the ICE.  This is because WARNINGS do not halt the compilation process.  For this case it's obviously a mistake.

It is interesting to see how  the NAG compiler handles this.  Notice that nagfor emits a warning for the result not being set, continues to compile but instead of getting an Internal Compiler Error it emits a final ERROR where that function is referenced.  The error message is a bit cryptic.  

nagfor Ice5623_Example.f90 
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203
Warning: Ice5623_Example.f90, line 16: Result THIS of function CONSTRUCTOR has not been assigned a value
[NAG Fortran Compiler normal termination, 1 warning]
Ice5623_Example.f90: In function ‘ice5623_example_MP_configure’:
Ice5623_Example.f90:22:10: error: invalid type argument of unary ‘*’ (have ‘__NAGf90_LPDT_Pointer’)
   22 |         this%model = constructor(integer1*integer2)
      |          ^~~~~~~~~~~~~~

 

We do not want a compiler to ICE even though the code is obviously invalid and reported with warnings as invalid.  I will write up a bug report but obviously at very low priority as the code is invalid and an appropriate and understandable warning was emitted.  Thank you for sending this to us.  I will post the bug ID shortly.

  

0 Kudos
Ron_Green
Moderator
1,292 Views

I want to open a discussion with my team about this code.  Should the lack of RESULT setting be an ERROR level event instead of a WARNING level?  I can envision arguments for and against making it an ERROR level.  We'll discuss this at a future team meeting. 

0 Kudos
WileyOne
Novice
1,081 Views

Thank you for looking at this, @Ron_Green. Our team has no need for this operation, so it's not urgent to us; I just wanted to be a responsible citizen and report the crash.

 

A minor change to the example shows that the warning and ICE are unrelated. The following still produces the crash:

module Ice5623_Example

    type :: SomeSystem(nStates)
        integer, len :: nStates
        integer :: ii
    end type

    type :: SomeClass
        type(SomeSystem(:)), allocatable :: model
    end type

    contains

    function constructor(nStates) result(this)
        integer                   :: nStates
        type(SomeSystem(nStates)) :: this
        this%ii = 7
    end function

    subroutine configure(this, integer1, integer2)
        type(SomeClass) :: this
        integer         :: integer1, integer2

        this%model = constructor(integer1*integer2)
    end subroutine

end module

However, simply saving the result of the multiplication off to a temporary variable and then passing that to the constructor resolves the issue:

module Ice5623_Example

    type :: SomeSystem(nStates)
        integer, len :: nStates
        integer :: ii
    end type

    type :: SomeClass
        type(SomeSystem(:)), allocatable :: model
    end type

    contains

    function constructor(nStates) result(this)
        integer                   :: nStates
        type(SomeSystem(nStates)) :: this
        this%ii = 7
    end function

    subroutine configure(this, integer1, integer2)
        type(SomeClass) :: this
        integer         :: integer1, integer2

        integer :: ii
        ii = integer1*integer2

        this%model = constructor(ii)
    end subroutine

end module

Regarding the warning ("the return value of this FUNCTION has not been defined") in my original post, it's not obvious to me that the code is invalid. A cursory look at the 2018 standard reveals nothing about this, but I have not looked through all of it. I will defer to those more knowledgeable on the topic.

0 Kudos
Ron_Green
Moderator
1,053 Views

the bug ID is CMPLRLLVM-68777


0 Kudos
Reply