This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/47474] New: Wrong code with allocatable scalar, allocatable components as function result
- From: "burnus at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 26 Jan 2011 13:13:23 +0000
- Subject: [Bug fortran/47474] New: Wrong code with allocatable scalar, allocatable components as function result
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47474
Summary: Wrong code with allocatable scalar, allocatable
components as function result
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: burnus@gcc.gnu.org
CC: janus@gcc.gnu.org
Blocks: 47455
Found as part of PR 47455. For the following program
function find_y() result(res)
type(tx), allocatable :: res
! do something sensible such as "allocate(res)"
end function find_y
the dump looks as follows
find_y ()
{
struct tx * res;
res.i.data = 0B; /* <<<< WRONG. */
res = 0B;
/* some code. */
return res;
}
If one does not use a RESULT variable but "find_y" as result variable, the dump
looks as follows:
find_y ()
{
__result_find_y.i.data = 0B; /* Note: 1. */
return __result_find_y;
}
Note 1: Unless "find_y" is used (e.g. "allocate(find_y)") the function is
generated with an empty body.
For some reason, the example program below does not crash here with gfortran
4.5/4.6, but the dump is wrong and I am sure it can cause problems in certain
cases. The example of bug 47455 comment 4 does crash - and I believe(d) that it
is due to this bug.
program test
type :: tx
integer, dimension(:), allocatable :: i
end type tx
type(tx) :: x
x = find_y()
if (allocated(x%i)) call abort()
contains
function find_y() result(res)
type(tx), allocatable :: res
allocate(res)
end function find_y
end program test