With a recent gfortran, the following compiles, but generates the wrong results: REAL,TARGET :: x CALL s3(f(x)) CONTAINS FUNCTION f(a) REAL,POINTER :: f REAL,TARGET :: a f => a END FUNCTION SUBROUTINE s3(targ) REAL,TARGET :: targ REAL,POINTER :: p p => targ IF (.NOT. ASSOCIATED(p,x)) CALL ABORT() END SUBROUTINE END
The problem is: s3(f(x)) which is translated as { real4 D.1254; D.1254 = *f (&x); s3 (&D.1254); } instead of D.1254 = f(&x)
(In reply to comment #1) > real4 D.1254; > D.1254 = *f (&x); > s3 (&D.1254); > } > instead of > D.1254 = f(&x) Funnily enough, I have been hit by the same problem in implementing procedure pointers. I will attempt to come to grips with it. Paul
This fixes the bug (and PR31209) and regtests OK. Will package it up as a submission tomorrow morning. Index: gcc/fortran/trans-expr.c =================================================================== *** gcc/fortran/trans-expr.c (revision 122943) --- gcc/fortran/trans-expr.c (working copy) *************** gfc_conv_function_call (gfc_se * se, gfc *** 2074,2083 **** --- 2074,2091 ---- /* Argument list functions %VAL, %LOC and %REF are signalled through arg->name. */ conv_arglist_function (&parmse, arg->expr, arg->name); + else if ((e->expr_type == EXPR_FUNCTION) + && e->symtree->n.sym->attr.pointer + && fsym && fsym->attr.target) + { + gfc_conv_expr (&parmse, e); + parmse.expr = build_fold_addr_expr (parmse.expr); + } else { gfc_conv_expr_reference (&parmse, e); if (fsym && fsym->attr.pointer + && fsym->attr.flavor != FL_PROCEDURE && e->expr_type != EXPR_NULL) { /* Scalar pointer dummy args require an extra level of Paul
*** Bug 31211 has been marked as a duplicate of this bug. ***
Subject: Bug number PR31200 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-03/msg01595.html
Subject: Bug 31200 Author: pault Date: Sat Mar 24 12:30:58 2007 New Revision: 123183 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123183 Log: 2007-03-24 Paul Thomas <pault@gcc.gnu.org> PR fortran/31215 * trans-expr.c (gfc_apply_interface_mapping_to_expr): Return int result that is non-zero if the expression is the function result. Only the characteristics of the result expression can be used in a procedure interface, so simplify LEN in situ using its character length. PR fortran/31219 PR fortran/31200 * trans-expr.c (gfc_conv_function_call): Do not use gfc_conv_expr_reference for actual pointer function with formal target because a temporary is created that does not transfer the reference correctly. Do not indirect formal pointer functions since it is the function reference that is needed. 2007-03-24 Paul Thomas <pault@gcc.gnu.org> PR fortran/31219 * gfortran.dg/pointer_function_actual_1.f90: New test. PR fortran/31200 * gfortran.dg/pointer_function_actual_2.f90: New test. PR fortran/31215 * gfortran.dg/result_in_spec_1.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/pointer_function_actual_1.f90 trunk/gcc/testsuite/gfortran.dg/pointer_function_actual_2.f90 trunk/gcc/testsuite/gfortran.dg/result_in_spec_1.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog
Fixed on trunk Paul
Subject: Bug 31200 Author: pault Date: Sat Mar 24 14:17:34 2007 New Revision: 123184 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123184 Log: 2007-03-24 Paul Thomas <pault@gcc.gnu.org> PR fortran/31215 * trans-expr.c (gfc_apply_interface_mapping_to_expr): Return int result that is non-zero if the expression is the function result. Only the characteristics of the result expression can be used in a procedure interface, so simplify LEN in situ using its character length. PR fortran/31219 PR fortran/31200 * trans-expr.c (gfc_conv_function_call): Do not use gfc_conv_expr_reference for actual pointer function with formal target because a temporary is created that does not transfer the reference correctly. Do not indirect formal pointer functions since it is the function reference that is needed. 2007-03-24 Paul Thomas <pault@gcc.gnu.org> PR fortran/31219 * gfortran.dg/pointer_function_actual_1.f90: New test. PR fortran/31200 * gfortran.dg/pointer_function_actual_2.f90: New test. PR fortran/31215 * gfortran.dg/result_in_spec_1.f90: New test. Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gfortran.dg/pointer_function_actual_1.f90