https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125263
Bug ID: 125263
Summary: Error with intrinsic assignment involving allocatable
array of user-defined type that has an allocatable
array component
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: b.j.braams at cwi dot nl
Target Milestone: ---
A small demonstration program follows, but the core of the problem is this.
```
type :: Foo_Type
integer, allocatable :: x(:)
end type Foo_Type
class (Foo_Type), allocatable :: fv(:), f
```
After creating and initializing f and fv(:) to different values an assignment
`fv(0) = f` is done (with suitable type guard). It appears that under gfortran
14.2.1
the component f%x is not copied, as is shown by the code output '0 1'.
The expected result '1 1' is obtained using Intel ifx and also using gfortran
13.3.0
on Ubuntu. Demonstration program follows.
```
program Main
implicit none (type, external)
type :: Foo_Type
integer, allocatable :: x(:)
end type Foo_Type
class (Foo_Type), allocatable :: fv(:), f
integer :: nx = 2, nf = 3, i
! Create fv(:) with all component vectors initialized to 0.
allocate (Foo_Type::fv(0:nf-1))
do i = 0, nf-1
allocate (fv(i)%x(0:nx-1))
fv(i)%x(:) = 0
end do
! Create f with f%x(:) equal to 1.
allocate (Foo_Type::f)
allocate (f%x(0:nx-1))
f%x(:) = 1
! Use intrinsic assignment to copy f to fv(0).
! The desired assignment fv(0) = f needs a type guard.
associate (ft => fv(0))
select type (ft)
type is (Foo_Type)
ft = f
class default
error stop 'select type (ft): type error'
end select
end associate
! Verify the copy on the element x(0).
write (*,*) fv(0)%x(0), f%x(0)
! Mystery error with gfortran 14.2.1 on Red Hat Linux.
! The expected output is '1 1'. The actual output is '0 1'.
stop
end program Main
```
$ gfortran -v Test.f90
Driving: gfortran -v Test.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-14.2.1-20240912/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.1 20240912 (Red Hat 14.2.1-3) (GCC)
COLLECT_GCC_OPTIONS='-v' '-foffload-options=-l_GCC_gfortran'
'-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
/usr/libexec/gcc/x86_64-redhat-linux/14/f951 Test.f90 -quiet -dumpdir a-
-dumpbase Test.f90 -dumpbase-ext .f90 -mtune=generic -march=x86-64 -version
-foffload-options=-l_GCC_gfortran -foffload-options=-l_GCC_m
-fintrinsic-modules-path /usr/lib/gcc/x86_64-redhat-linux/14/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o /tmp/cciTyxpc.s
GNU Fortran (GCC) version 14.2.1 20240912 (Red Hat 14.2.1-3)
(x86_64-redhat-linux)
compiled by GNU C version 14.2.1 20240912 (Red Hat 14.2.1-3), GMP
version 6.2.1, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.24-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-foffload-options=-l_GCC_gfortran'
'-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
as -v --64 -o /tmp/ccnO7g4L.o /tmp/cciTyxpc.s
GNU assembler version 2.41 (x86_64-redhat-linux) using BFD version version
2.41-38.fc40
Reading specs from /usr/lib/gcc/x86_64-redhat-linux/14/libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-foffload-options=-l_GCC_gfortran'
'-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a-'
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/14/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/14/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/ufs/braams/intel/oneapi/tcm/1.4/lib/:/ufs/braams/intel/oneapi/umf/0.11/lib/:/ufs/braams/intel/oneapi/mpi/2021.16/lib/:/ufs/braams/intel/oneapi/compiler/2025.2/lib/:/usr/lib/gcc/x86_64-redhat-linux/14/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-foffload-options=-l_GCC_gfortran'
'-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a.'
/usr/libexec/gcc/x86_64-redhat-linux/14/collect2 -plugin
/usr/libexec/gcc/x86_64-redhat-linux/14/liblto_plugin.so
-plugin-opt=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccU3ywdW.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath
-plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id
--no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-redhat-linux/14/crtbegin.o
-L/usr/lib/gcc/x86_64-redhat-linux/14
-L/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64 -L/ufs/braams/intel/oneapi/tcm/1.4/lib
-L/ufs/braams/intel/oneapi/umf/0.11/lib
-L/ufs/braams/intel/oneapi/mpi/2021.16/lib
-L/ufs/braams/intel/oneapi/compiler/2025.2/lib
-L/usr/lib/gcc/x86_64-redhat-linux/14/../../.. /tmp/ccnO7g4L.o -lgfortran -lm
-lgcc_s -lgcc --as-needed -lquadmath --no-as-needed -lm -lc -lgcc_s -lgcc
/usr/lib/gcc/x86_64-redhat-linux/14/crtend.o
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../lib64/crtn.o
COLLECT_GCC_OPTIONS='-v' '-foffload-options=-l_GCC_gfortran'
'-foffload-options=-l_GCC_m' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
'-dumpdir' 'a.'