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

ifx wrong result with EXTENDS_TYPE_OF in array constructor at -O2

pums974
New User
19 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
0 Replies
Reply