https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116656
Bug ID: 116656
Summary: Nested pointer assignment is causing a SIGBUS error.
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: cianciosamr at ornl dot gov
Target Milestone: ---
The following test program is failing with the function foo_construct called
twice and ending with a SIGBUS error. The target machine is MacOS 14.6.1
running on an Apple M1 Pro.
% cat test.f90
module test
implicit none
type :: foo
end type
contains
function make()
implicit none
class (foo), pointer :: make
make => foo_construct()
end function
function foo_construct()
implicit none
class (foo), pointer :: foo_construct
allocate(foo_construct)
write (*,*) 'construct_foo'
end function
end module
% cat test_prog.f90
program test_construct
use test
implicit none
class (foo), pointer :: foo_instant
foo_instant => make()
deallocate(foo_instant)
end program
% gfortran -Wall -Wextra -c test.f90
% gfortran -Wall -Wextra -c test_prog.f90
% gfortran -Wall -Wextra -o test_prog *.o
% ./test_prog
construct_foo
construct_foo
Program received signal SIGBUS: Access to an undefined portion of a memory
object.
Backtrace for this error:
#0 0x102a7eccf
#1 0x102a7dd23
#2 0x18cd7a583
#3 0x102443cff
#4 0x102443d57
zsh: bus error ./test_prog
% gfortran --version
GNU Fortran (GCC) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Note: If I change the functions to use result variables, the code works as
expected.