re PR fortran/19673 (pointer function with RESULT specified returns pointer to "ptr...
authorTobias Schlüter <tobi@gcc.gnu.org>
Fri, 4 Mar 2005 21:03:46 +0000 (22:03 +0100)
committerTobias Schlüter <tobi@gcc.gnu.org>
Fri, 4 Mar 2005 21:03:46 +0000 (22:03 +0100)
fortran/
PR fortran/19673
* trans-expr.c (gfc_conv_function_call): Correctly dereference
argument from a pointer function also if it has a result clause.

testsuite/
PR fortran/19673
* gfortran.dg/func_result_1.f90: New test.

From-SVN: r95901

gcc/fortran/ChangeLog
gcc/fortran/trans-expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/func_result_1.f90 [new file with mode: 0644]

index b612122..db94aa6 100644 (file)
@@ -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 685a9f9..b79d074 100644 (file)
@@ -1220,7 +1220,8 @@ gfc_conv_function_call (gfc_se * se, gfc_symbol * sym,
      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
index adc463c..bf945a0 100644 (file)
@@ -1,3 +1,8 @@
+2005-03-04  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>
+
+       PR fortran/19673
+       * gfortran.dg/func_result_1.f90: New test.
+
 2005-03-04  Ben Elliston  <bje@au.ibm.com>
 
        * gcc.misc-tests/options.exp: New test.
diff --git a/gcc/testsuite/gfortran.dg/func_result_1.f90 b/gcc/testsuite/gfortran.dg/func_result_1.f90
new file mode 100644 (file)
index 0000000..ce3c2e4
--- /dev/null
@@ -0,0 +1,19 @@
+! { 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