This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch, fortran] PR44582 - gfortran generates wrong results due to wrong ABI in function with array return


On Mon, Jun 28, 2010 at 9:47 AM, Paul Richard Thomas
<paul.richard.thomas@gmail.com> wrote:
> This PR is marked as critical.
>
> For as long as I can remember, gfortran has made assignments of the kind:
> lhs_array = array_valued_function (args,...)
> without a temporary, except when, for example, there is a dependency
> between the lhs_array and one of the arguments.
>
> The reporter (Yin Ma of Absoft) noticed that aliasing could occur
> between the function result and other forms of association. ?The
> example below, due to Tobias Burnus, illustrates this.
>
> program test
> ?implicit none
> ?integer :: a(5)
> ?a = 5
> ?a = f() ? ? ? ? ? ? ? ? ? ?! assignment
> ?print *, a
> ?a = 5
> ?print *, f() ? ? ? ? ? ? ? ! print
> contains
> ?function f()
> ? ? integer :: f(size(a))
> ? ? f = -5 ? ? ? ? ? ? ? ? ! Resets 'a' to -5 in the assignment
> ? ? f = a - f ? ? ? ? ? ? ?! Gives 0 for the assignment and 10 for the print
> ?end function f
> end program test
>
> This program prints a row of 0's followed by a row of 10's, whereas
> two rows of 10's is the correct result.
>
> The attached patch fixes this by being much more restrictive in the
> use of this optimization. ?In fact, it is still conservative as the
> 'TODO' in the new function indicates. ?The testcase incorporates the
> above and a number of other aliasing situations. ?Trunk currently
> fails all the cases that need a temporary.
>
> Bootstrapped and regtested on FC9/x86_64 - OK for trunk, 4.5,4.4 and 4.3?
>
> Cheers
>
> Paul
>
> 2010-06-28 ?Paul Thomas ?<pault@gcc.gnu.org>
>
> ? ? ? ?PR fortran/44582
> ? ? ? ?* trans-expr.c (arrayfunc_assign_needs_temporary): New function
> ? ? ? ?to determine if a function assignment can be made without a
> ? ? ? ?temporary.
> ? ? ? ?(gfc_trans_arrayfunc_assign): Move all the conditions that
> ? ? ? ?suppress the direct function call to the above new functon and
> ? ? ? ?call it.
>
> 2010-06-28 ?Paul Thomas ?<pault@gcc.gnu.org>
>
> ? ? ? ?PR fortran/44582
> ? ? ? ?* gfortran.dg/aliasing_array_result_1.f90 : New test.
>

This caused:

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

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]