- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
Link Copied

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page