public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47592] New: Multiple function invocation with ALLOCATE (SOURCE=REPEAT('x',bar()))
@ 2011-02-02 22:38 tkoenig at gcc dot gnu.org
  2011-02-03  7:43 ` [Bug fortran/47592] " paul.richard.thomas at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2011-02-02 22:38 UTC (permalink / raw)
  To: gcc-bugs

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...


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-02-06 14:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-02 22:38 [Bug fortran/47592] New: Multiple function invocation with ALLOCATE (SOURCE=REPEAT('x',bar())) tkoenig at gcc dot gnu.org
2011-02-03  7:43 ` [Bug fortran/47592] " paul.richard.thomas at gmail dot com
2011-02-03 21:10 ` pault at gcc dot gnu.org
2011-02-06 14:25 ` pault at gcc dot gnu.org
2011-02-06 15:07 ` pault at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).