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

ifx wrong result with EXTENDS_TYPE_OF in array constructor at -O2

pums974
Beginner
84 Views

I observe a wrong result with ifx when using EXTENDS_TYPE_OF on elements of a polymorphic allocatable array inside an array constructor. The issue appears with optimization enabled, at least with -O2.

Minimal reproducer:

program bug_report
    implicit none

    type :: base_type
    end type base_type

    class(base_type), allocatable :: polymorphic_array(:)
    type(base_type) :: element
    logical :: test(2)

    allocate(polymorphic_array(2))

    test = [ &
        extends_type_of(polymorphic_array(1), element), &
        extends_type_of(polymorphic_array(2), element) &
    ]

    print *, "scalar 1:", extends_type_of(polymorphic_array(1), element)
    print *, "scalar 2:", extends_type_of(polymorphic_array(2), element)
    print *, "array:   ", test

    if (.not. all(test)) error stop "wrong result"
end program bug_report

Expected output:

 scalar 1: T
 scalar 2: T
 array:    T T

Actual output with ifx -O2:

 scalar 1: T
 scalar 2: T
 array:    F T
ERROR STOP wrong result

The two scalar calls to EXTENDS_TYPE_OF return the expected value, but the same expressions evaluated inside the array constructor assigned to test produce an incorrect first element.

Compilation commands used:

ifx -O1 bug_report.f90 && ./a.out
ifx -O2 bug_report.f90 && ./a.out
gfortran -O1 bug_report.f90 && ./a.out gfortran -O2 bug_report.f90 && ./a.out

Observed behavior:

ifx -O1: correct result
ifx -O2: wrong result, first element of test is F
gfortran -O1: correct result
gfortran -O2: correct result

Compiler version:

ifx (IFX) 2025.0.4 20241205

System information:

OS: Arch Linux

 

0 Kudos
3 Replies
Shiquan_Su
Moderator
52 Views

We are taking a closer look at that.

LitSurfTry
Beginner
28 Views

is this thread is real or fake... If it wont help, then insuficient data reported as thread to messaging.

WRONG! test = [ &
        extends_type_of(polymorphic_array(1), element),<--------!!!!!!!! &
        extends_type_of(polymorphic_array(2), element) &
    ]
test = [ &
        extends_type_of(polymorphic_array(1), element) &
        extends_type_of(polymorphic_array(2), element) &
    ]
WRONG!    print *, "array:   ", test
    print *, "array:*", test

OR

    print *, "array:array(1)", test
    print *, "array:array(2)", test

if not all (* is missing or 1 2) then error

goodluck.

0 Kudos
pums974
Beginner
3 Views

For completeness, I have a different result with the latest version of ifx

ifx (IFX) 2026.0.0 20260331

scalar 1: T
scalar 2: T
array: F F
wrong result

 now the whole array is False for some reason.

0 Kudos
Reply