Message ID | 4D38B0A2.8070408@net-b.de |
---|---|
State | New |
Headers | show |
On Thu, Jan 20, 2011 at 11:01:06PM +0100, Tobias Burnus wrote: > A rather obvious patch for an ICE occurring for invalid code: > > ptr => f() > > requires that "f()" returns a pointer. Currently, gfortran first happily > accepts "f()" if the result variable has the target attribute - and then > it ICEs. (Cf. PR for the quotes from the standard.) > > Build on x86-64-linux and currently regtesting (so far successfully). > OK for the trunk? > OK. I'll suggest a slight wording change in the error message. Currently, you have "Pointer assignment target expression" which I find a little awkward. Perhaps, + gfc_error ("Target expression in pointer assignment " + "at %L must deliver a pointer result", + &rvalue->where); Whatever you decide to commit is fine with me.
2011-01-20 Tobias Burnus <burnus@net-b.de> PR fortran/47377 * expr.c (gfc_check_pointer_assign): Reject expr data-targets without pointer attribute. 2011-01-20 Tobias Burnus <burnus@net-b.de> PR fortran/47377 * gfortran.dg/pointer_target_4.f90: New. diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 3f1141a..a4e48c8 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3507,6 +3507,15 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) lvalue->symtree->n.sym->attr.subref_array_pointer = 1; attr = gfc_expr_attr (rvalue); + + if (rvalue->expr_type == EXPR_FUNCTION && !attr.pointer) + { + gfc_error ("Pointer assignment target expression " + "at %L must deliver a pointer result", + &rvalue->where); + return FAILURE; + } + if (!attr.target && !attr.pointer) { gfc_error ("Pointer assignment target is neither TARGET " diff --git a/gcc/testsuite/gfortran.dg/pointer_target_4.f90 b/gcc/testsuite/gfortran.dg/pointer_target_4.f90 new file mode 100644 index 0000000..cda3453 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pointer_target_4.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } +! +! PR fortran/47377 +! +! Contributed by <thenlich@users.sourceforge.net> +! +program testgferr + real, pointer :: y + y => f() ! { dg-error "must deliver a pointer result" } +contains + function f() + real :: f + f = 5 + end function f +end program testgferr