[Bug fortran/47592] New: Multiple function invocation with ALLOCATE (SOURCE=REPEAT('x',bar()))
tkoenig at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Feb 2 22:38:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47592
Summary: Multiple function invocation with ALLOCATE
(SOURCE=REPEAT('x',bar()))
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: tkoenig@gcc.gnu.org
CC: pault@gcc.gnu.org
ig25@linux-fd1f:/tmp> cat foo.f90
module foo
implicit none
contains
function bar()
integer bar
integer :: i=9
i = i + 1
bar = i
end function bar
end module foo
program note7_35
use foo
implicit none
character(:), allocatable :: name
character(:), allocatable :: src
integer n
n = 10
allocate(name, SOURCE=repeat('x',bar()))
if (name .ne. 'xxxxxxxxxx') call abort
if (len (name) .ne. 10 ) call abort
print *,bar()
end program note7_35
ig25@linux-fd1f:/tmp> gfortran foo.f90
ig25@linux-fd1f:/tmp> ./a.out
12
The output should be 11.
Paul, the cleanest way to resolve this would be to replace the call
to gfc_copy_expr in your recent patch with a new function which
goes something like this (incomplete and untested...)
void gfc_freeze_expression (gfc_expr *oe, gfc_expr *ne, gfc_code **c)
{
if (oe->expr_type == EXPR_CONSTANT || oe->expr_type == EXPR_VARIABLE)
{
ne = gfc_copy_expr (oe);
return;
}
/* Create a new variable with the same type as oe,
create an assignment where oe is assigned to that
variable and insert it before the current statement,
then replace oe with that variable. */
}
This is a function that I've been meaning to write for the
front end passes for some time...
More information about the Gcc-bugs
mailing list