Nvfortran 26.9: structure constructor as the value of a polymorphic allocatable component: ICE (`mkexpr1: bad id 14`) or a segfaulting executable

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_t has a second component, e.g. real :: h = -1. after c, 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 (and print *, e%c%v), it compiles and prints v = 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.

Hi Pedro,

I was able to reproduce the issue here and filed a report, TPR #39149. We’ll have engineering take a look.

Now since the code does work with our upcoming LLVM based nvfortran, and the current PGI based nvfortran doesn’t fully support F2008, there may be a possibility that they defer this one. Though, they have been working hard to get all reports fixed, so hopefully, but letting you know just in case.

-Mat