https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119273
Bug ID: 119273
Summary: subclass can not correctly access to superclass in
associate statement
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: xingjingwei666 at gmail dot com
Target Milestone: ---
Test case:
module test_module
type :: test_type_father
integer :: val
end type test_type_father
type, extends(test_type_father) :: test_type_child
contains
procedure :: test_function
end type test_type_child
contains
function test_function(a) result(out)
class(test_type_child), intent(in) :: a
integer :: out
out = a%val
end function
end module
program test
use test_module
implicit none
type(test_type_child) :: a
integer :: temp_int(1,1)
a%val = 1
associate(temp => temp_int(:,a%test_function()))
end associate
end program test
compile flag:
-fcheck=bounds
If compile without checking bounds, it works fine. But if "-fcheck=bounds" is
added into compile flag, it will crush at runtime at associate statement.
Error message is "Index '-788478977' of dimension 2 of array 'temp_int' outside
of expected range (1:1)", but val is set to 1 just before the associate
statement.
It seems that subclass can't correctly access component of superclass in
subclass's type-bounded procedure. Because in my real program, I use gdb(gdb is
running on WSL2) to check what happened, the result is segment fault. When I
check the value of superclass, it is empty rather than non-initialized random
number.
It occurs only on gfortran 14.2.0, I found there is no such problem on 12.4.0
and 13.3.0.
My platform is MacBook Pro(M4 pro), but I also test it on WSL2(core i7 11700)
and the result is the same.
gfortran -v:
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/14.2.0_1/bin/../libexec/gcc/aarch64-apple-darwin24/14/lto-wrapper
Target: aarch64-apple-darwin24
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc
--libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran,m2 --program-suffix=-14
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 14.2.0_1'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin24
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Homebrew GCC 14.2.0_1)