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

IFX compiler bug with elemental derived type constructors

DataScientist
Valued Contributor I
1,231 Views

The following code is valid but yields a segmentation fault with IFX 2025.2.

 

module con_mod

type :: con_type
integer, allocatable :: val
end type

interface con_type
module procedure :: con_maker
end interface

contains

pure elemental function isequal(con, value) result(itis)
type(con_type), intent(in) :: con, value
logical :: itis
itis = con%val == value%val
end function

pure elemental function con_maker(val) result(con)
!pure function con_maker(val) result(con)
integer, intent(in) :: val
type(con_type) :: con
con%val = val
end function

end module con_mod

use con_mod, only: con_type, isequal

implicit none

type(con_type), allocatable :: values(:)

values = [con_type(1), con_type(2)]
print *, isequal(con_type(1), values)

end

 

 

0 Kudos
4 Replies
DataScientist
Valued Contributor I
1,225 Views

It's unbelievable how many times over the past week I tried to post this error here, but I was tagged as s--p--a--m immediately. I had to cut extensive information surrounding this error to allow its posting here. I do not know what triggers the s*** detector of this forum, but one thing is for sure: This forum currently has a terrible automated s*** detector.

0 Kudos
DataScientist
Valued Contributor I
1,224 Views

Back to the problem, the issue lies in the elemental attribute of the derived type constructor. If you remove it, the segmentation fault error in the function iequal() will be resolved. This error does not occur with ifort or gfortran.

0 Kudos
JohnNichols
Valued Contributor III
1,041 Views
module con_mod

type :: con_type
integer, allocatable :: val
end type

interface con_type
module procedure :: con_maker
end interface

contains

pure elemental function isequal(con, value) result(itis)
type(con_type), intent(in) :: con, value
logical :: itis
itis = con%val == value%val
end function

pure elemental function con_maker(val) result(con)
!pure function con_maker(val) result(con)
integer, intent(in) :: val
type(con_type) :: con
con%val = val
end function

end module con_mod

use con_mod, only: con_type, isequal

implicit none

type(con_type), allocatable :: values(:)

values = [con_type(1), con_type(2)]
print *, isequal(con_type(1), values)

end

It is way easier to read if you use the insert code </> button. 

0 Kudos
DataScientist
Valued Contributor I
1,038 Views

Blame the automatic spam detector of this forum for the lack of format!

0 Kudos
Reply