This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/37199] array assignment from function writes out of bounds
- From: "domob at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Sep 2008 19:00:39 -0000
- Subject: [Bug fortran/37199] array assignment from function writes out of bounds
- References: <bug-37199-16624@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #5 from domob at gcc dot gnu dot org 2008-09-07 19:00 -------
program bounds_issue
real, pointer :: pdf0(:)
allocate(pdf0(0:282))
pdf0 = f(pdf0)
contains
function f(x)
real, intent(in) :: x(0:) ! x(1:), f(1:...) works
real :: f(0:ubound(x,dim=1)) ! x(-1:), f(-1:...) crashes
f = 0.0
end function
end program bounds_issue
---
For the temporary array holding the result and the loop assigning back to pdf0,
the bounds of f(0:ubound(x,dim=1)) are used. The interface mapping of x in the
upper bound however does not supply an array-spec to the symbol, and thus
UBOUND(x) returns the number of elements in x rather than the real upper bound
matching the fixed lower-bound of 0 as for an entity not being a full array.
Thus, the loop starts at 0 because of the constant lower bound but runs one
element too far because the upper bound is evaluated as if the lower was 1.
This leads to the segfault in any case but when 1 is indeed the lower bound.
It seems to be possible to simply copy the array-spec to new_sym in
gfc_add_interface_mapping, I'm working this out at the moment.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37199