Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29280 Discussions

IFX COMPILER BUG: elemental functions

DataScientist
Valued Contributor I
123 Views

The following code is valid and generates the correct result with ifort and gfortran, but yields a segmentation fault with ifx 2025.2 and most likely the older versions (it has taken me a year to isolate and reproduce this bug from a multimillion-line codebase):

module str_mod

    type :: str_type
        character(:), allocatable :: val
    end type

    interface str_type
        module procedure :: str_maker
    end interface

contains

    pure elemental function endswith(str, suffix) result(itis)
        type(str_type), intent(in) :: str, suffix
        logical :: itis
        itis = str%val(max(1, len(str%val) - len(suffix%val) + 1) : len(str%val)) == suffix%val
    end function

    pure elemental function str_maker(val) result(str)
        character(*), intent(in) :: val
        type(str_type) :: str
        str%val = trim(val)
    end function

end module str_mod

use str_mod, only: str_type, endswith

implicit none

type(str_type), allocatable :: suffixes(:)

suffixes = [str_type('str1'), str_type('str2')]
!print *, suffixes(1)%val, suffixes(2)%val
print *, endswith(str_type('str1'), suffixes)

end

If one comments out the elemental constructor `str_maker` of the `str_type` derived type, the code compiles and runs successfully. But this is undesired, because the code is valid, and in practice, `str_maker` is far more complex than this simple bug reproducer above.

The segmentation fault occurs at line 16 inside the elemental function `endswith`. Here is a link to compile, run, and compare with other compiler outputs: https://godbolt.org/z/j5Eecr6rv

Thank you for the impressive compiler and for any help in resolving this bug (or error).

0 Kudos
0 Replies
Reply