- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is my third attempt at posting a potential IFX compiler bug in the hope of not being flagged as s-p-a-m again:
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
! This elemental attribute triggers segfault error in the above function `endswith`.
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 removes the elemental attribute of the constructor str_maker of the str_type derived type, the code compiles and runs successfully. However, this should not be needed because the code is valid; 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 the godbolt website to compile, run, and compare with other compiler outputs (now removed, because I believe this link is what triggers the s-p-a-m detector of this forum). Visit the website yourself and paste the code there.)
This error is not bound to strings alone. The same segfault error occurs if one uses a container of allocatable scalar other than a string.
Thank you for the impressive compiler and for any help in resolving this bug (or error).
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FWIW, I have seen all three attempts. I have used Intel Fortran oneAPI 2025.0.0 on Windows and the program fails on line 16.
If I replace the str_type constructor by a variable that is initialised with the same value, the program works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess the moderators acted on my pending spam abuse reports.

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