https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96910
Bug ID: 96910
Summary: intrinsic assignment does not duplicate allocatable
component of nested derived type
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: dlhough at gmail dot com
Target Milestone: ---
In the following code, I would expect a new allocation to be made for copy%nest
in the assignment copy=original in the same fashion as a new allocation is
created for copy%child. However, copy%nest and original%nest are at the same
address following the assignment as demonstrated by the print statements.
module TestAllocatableCopy_m
implicit none
private
type, public :: Child_t
end type
type, public :: Test_t
type(Test_t), allocatable :: nest
type(Child_t), allocatable :: child
end type
end module
program TestAllocatableCopy
use TestAllocatableCopy_m
implicit none
type(Test_t), target :: original
type(Test_t), target :: copy
class(Test_t), pointer :: nestPtr
class(Child_t), pointer :: childPtr
allocate(original%nest)
allocate(original%child)
nestPtr => original%nest
childPtr => original%child
copy = original
! prints "Child: F" with GCC 10.2
print *, "Child:", associated(childPtr, copy%child)
! prints "Nest: T" with GCC 10.2
! expected: "Nest: F"
print *, "Nest:", associated(nestPtr, copy%nest)
end program
Compilation command:
gfortran -v -save-temps -Wall -Wextra ../../test/TestAllocatableCopy.f90
Driving: gfortran -v -save-temps -Wall -Wextra
../../test/TestAllocatableCopy.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib
--libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++,d --with-isl
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id
--enable-lto --enable-multilib --enable-plugin --enable-shared
--enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-libunwind-exceptions --disable-werror
gdc_include_dir=/usr/include/dlang/gdc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/f951
../../test/TestAllocatableCopy.f90 -quiet -dumpbase TestAllocatableCopy.f90
-mtune=generic -march=x86-64 -auxbase TestAllocatableCopy -Wall -Wextra
-version -fintrinsic-modules-path
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/finclude
-fpre-include=/usr/include/finclude/math-vector-fortran.h -o
TestAllocatableCopy.s
GNU Fortran (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version
4.1.0, MPC version 1.1.0, isl version isl-0.21-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 10.2.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 10.2.0, GMP version 6.2.0, MPFR version
4.1.0, MPC version 1.1.0, isl version isl-0.21-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
as -v --64 -o TestAllocatableCopy.o TestAllocatableCopy.s
GNU assembler version 2.35 (x86_64-pc-linux-gnu) using BFD version (GNU
Binutils) 2.35
Reading specs from
/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib/libgfortran.spec
rename spec lib to liborig
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/:/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-sa