This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran 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]

[gfortran, committed] Fix PR 19673: incorrect handling of POINTERreturn value


This fixes an oversight in the handling of the results of POINTER valued
functions.  I committed this as obvious together with the attached testcase
after bubblestrapping and testing.

The handling of functions with / without RESULT needs a cleanup which should
remove the need to look at both sym and sym->result in the modified if.  I
didn't implement this, as I'm not sure that would be appropriate for the 4.0
branch.  I will also commit this to the 4.0 branch once I've tested it there.

- Tobi

Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/ChangeLog,v
retrieving revision 1.342
diff -u -p -r1.342 ChangeLog
--- ChangeLog   4 Mar 2005 17:09:16 -0000       1.342
+++ ChangeLog   4 Mar 2005 20:54:37 -0000
@@ -1,4 +1,10 @@
-Steven G. Kargl  <kargls@comcast.net>
+2005-03-04  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/19673
+       * trans-expr.c (gfc_conv_function_call): Correctly dereference
+       argument from a pointer function also if it has a result clause.
+
+2005-03-04  Steven G. Kargl  <kargls@comcast.net>

        * expr.c (gfc_copy_shape_excluding): Change && to ||.

Index: trans-expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-expr.c,v
retrieving revision 1.38
diff -u -p -r1.38 trans-expr.c
--- trans-expr.c        23 Feb 2005 21:34:11 -0000      1.38
+++ trans-expr.c        4 Mar 2005 20:54:38 -0000
@@ -1220,7 +1220,8 @@ gfc_conv_function_call (gfc_se * se, gfc
      something like
         x = f()
      where f is pointer valued, we have to dereference the result.  */
-  if (sym->attr.pointer && !se->want_pointer && !byref)
+  if (!se->want_pointer && !byref
+      && (sym->attr.pointer || (sym->result && sym->result->attr.pointer)))
     se->expr = gfc_build_indirect_ref (se->expr);

   /* A pure function may still have side-effects - it may modify its
! { dg-do run }
! From PR 19673 : We didn't dereference the the result from POINTER
! functions with a RESULT clause
program ret_ptr
  if (foo(99) /= bar(99)) call abort ()
contains
  function foo (arg) result(ptr)
    integer :: arg
    integer, pointer :: ptr
    allocate (ptr)
    ptr = arg
  end function foo
  function bar (arg)
    integer :: arg
    integer, pointer :: bar
    allocate (bar)
    bar = arg
  end function bar
end  program ret_ptr

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