[Bug fortran/58310] New: Allocatable component arrays: Wrong code after calling a subroutine
burnus at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Sep 3 19:14:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58310
Bug ID: 58310
Summary: Allocatable component arrays: Wrong code after calling
a subroutine
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: burnus at gcc dot gnu.org
CC: pault at gcc dot gnu.org
As reported by James Spencer at
https://groups.google.com/forum/#!topic/comp.lang.fortran/VuFvOsLs6hE
The call to the subroutine causes copy-in/copy-out - and that somehow causes
that that access to invalid memory.
(Side remark: I think the copy-in/copy-out is required as we do not have byte
strides, just element-based strides. See
http://gcc.gnu.org/wiki/ArrayDescriptorUpdate)
Output of the code below:
1 1
2 2
in s1: 1 1
in s1: 2 2
0 0
21884992 0
Program received signal SIGABRT: Process abort signal.
When run under valgrind, the output is correct - but one gets two errors: Once
directly after the subroutine call:
==21383== Invalid read of size 4
==21383== at 0x4F15AB0: extract_int (write.c:440)
==21383== by 0x4F17020: write_integer (write.c:1250)
And at the very end:
==21383== Invalid free() / delete / delete[] / realloc()
Here is the code which causes the problems with GCC 4.3 to GCC 4.9:
program p
implicit none
type x_t
integer, allocatable :: v(:)
end type x_t
type y_t
type(x_t) :: x
end type y_t
type(y_t), allocatable, target :: y(:)
integer :: i
integer, parameter :: N=2
allocate(y(N))
do i = 1,N
allocate(y(i)%x%v(N))
y(i)%x%v = i
end do
do i = 1,N
write (6,*) y(i)%x%v
end do
call s1(y%x)
do i = 1,N
write (6,*) y(i)%x%v
end do
deallocate(y)
contains
subroutine s1(x)
type(x_t), intent(inout) :: x(:)
integer :: i
do i = 1, size(x)
print *, 'in s1: ', x(i)%v
end do
end subroutine s1
end program p
More information about the Gcc-bugs
mailing list