------- Comment #6 from burnus at gcc dot gnu dot org  2010-06-19 09:47 -------
(In reply to comment #0)
> the function with array return must create a temporary array to hold the
> returned value and transfer the value to destination array after function
> call.

> gfortran returns 5.0
> it should be 0.0 or a chaotic number.

Well, it is an arbitrary/chaotic/random number: In case of gfortran it happens
to be the previous value of the assignment (namely 5.0), but I do not see why
an always changing number - be once 0.0 or 1.0e88 or 42.0 is better. 


By the way, I have now filled PR 44589 as gfortran does not warn that the
return variable in "ddx" has not been initialized.



> O.K. I doublechecked the standard. The array declared does not need to be
> initialized in this case. So the return value could be any number. However,
> this kind of implementation should fail in a certian case. I am trying to
>  write a small example to prove this. I will post it later.


Thanks for alerting us of the following issue.

I believe the following program is an example where a temporary is needed as
first the RHS has to be evaluated before it is assigned to the LHS. Thus, the
optimization can be done - but only for PURE procedures.


The program below should print twice "10 10 10 10 10" but due to the bug, it
prints zeros for the first print and the tens only for the second print
statement.

program test
  implicit none
  integer :: a(5)
  a = 5
  a = f()
  print *, a
  a = 5
  print *, f()
contains
  function f()
     integer :: f(size(a))
     f = -5
     f = a - f
  end function f
end program test


The check is done in trans-expr.c's gfc_trans_arrayfunc_assign - here an extra
check (expr2->value.function.esym && expr2->value.function.esym->attr.pure)
seems to be needed.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org
OtherBugsDependingO|                            |34640
              nThis|                            |
             Status|RESOLVED                    |UNCONFIRMED
  GCC build triplet|x86-64                      |
   GCC host triplet|x86-64                      |
 GCC target triplet|x86-64                      |
           Keywords|                            |wrong-code
         Resolution|INVALID                     |
            Version|fortran-dev                 |4.6.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44582

Reply via email to