Hello,
In nvfortran 26.9, a structure constructor fails when its polymorphic allocatable component is given another structure constructor, ext_t(c=poly_t(...)). F2008 allows this: the component is allocated with the dynamic type of the value. Depending on the type, the result is an ICE or an executable that segfaults.
Environment: NVIDIA HPC SDK 26.9 (nvfortran 26.9-0 64-bit target on x86-64 Linux -tp cascadelake), Ubuntu 26.04.1 LTS. Same results at -O0, -O2 and -fast.
Reproducer
module m
implicit none
type :: sec_t
end type sec_t
type, extends(sec_t) :: poly_t
real :: v = 0.
end type poly_t
type :: ext_t
class(sec_t), allocatable :: c
end type ext_t
end module m
program p
use m
implicit none
type(ext_t) :: e
e = ext_t(c=poly_t(v=2.))
select type(c => e%c)
type is(poly_t)
print '(a,f4.1)', ' v = ',c%v
end select
end program p
$ nvfortran -O0 constructor_mre.f90
NVFORTRAN-S-0000-Internal compiler error. mkexpr1: bad id 14 (constructor_mre.f90: 16)
NVFORTRAN-S-1262-Type mismatch for component c in structure constructor ext_t. (constructor_mre.f90: 16)
NVFORTRAN-S-0000-Internal compiler error. mkexpr1: bad id 14 (constructor_mre.f90: 16)
0 inform, 0 warnings, 3 severes, 0 fatal for p
- If
ext_thas a second component, e.g.real :: h = -1.afterc, it compiles with a bogus warning,NVFORTRAN-W-0155-Mismatched data type for member h, and the executable segfaults. - With a non-polymorphic component,
type(poly_t), allocatable :: c(andprint *, e%c%v), it compiles and printsv = 2.0.
gfortran 15.2, ifx 2026.1 and LLVM Flang (20.1.8 and trunk, tested on Compiler Explorer) compile all these variants and print v = 2.0. In our code the same happened with allocate(s,source=ext_t(c=poly_t(...))).
Workaround: allocate the component separately, allocate(e%c,source=poly_t(v=2.)).
Thank you in advance!
Pedro
Written with the help of Claude Code.