diff options
author | Paul Thomas <pault@gcc.gnu.org> | 2013-01-13 08:57:46 +0000 |
---|---|---|
committer | Paul Thomas <pault@gcc.gnu.org> | 2013-01-13 08:57:46 +0000 |
commit | 899d52c6e21ab11ef716816a433c4c583e0052d1 (patch) | |
tree | 7af314adbc7890bb75e81fb6509028474e01ecd9 /gcc/fortran/expr.c | |
parent | 8816ac704c531d14de865a9f86098edac06554e7 (diff) | |
download | gcc-899d52c6e21ab11ef716816a433c4c583e0052d1.zip gcc-899d52c6e21ab11ef716816a433c4c583e0052d1.tar.gz gcc-899d52c6e21ab11ef716816a433c4c583e0052d1.tar.bz2 |
re PR fortran/54286 (Accepts invalid proc-pointer assignments involving proc-ptr function result)
2013-01-13 Paul Thomas <pault@gcc.gnu.org>
PR fortran/54286
* expr.c (gfc_check_pointer_assign): Ensure that both lvalue
and rvalue interfaces are presented to gfc_compare_interfaces.
Simplify references to interface names by using the symbols
themselves. Call gfc_compare_interfaces with s1 and s2 inter-
changed to overcome the asymmetry of this function. Do not
repeat the check for the presence of s1 and s2.
2013-01-13 Paul Thomas <pault@gcc.gnu.org>
PR fortran/54286
* gfortran.dg/proc_ptr_result_8.f90 : New test.
From-SVN: r195133
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r-- | gcc/fortran/expr.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 89ec1c5..3010dd9 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3506,7 +3506,11 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) if (comp) s1 = comp->ts.interface; else - s1 = lvalue->symtree->n.sym; + { + s1 = lvalue->symtree->n.sym; + if (s1->ts.interface) + s1 = s1->ts.interface; + } comp = gfc_get_proc_ptr_comp (rvalue); if (comp) @@ -3514,7 +3518,7 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) if (rvalue->expr_type == EXPR_FUNCTION) { s2 = comp->ts.interface->result; - name = comp->ts.interface->result->name; + name = s2->name; } else { @@ -3525,16 +3529,30 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr *rvalue) else if (rvalue->expr_type == EXPR_FUNCTION) { s2 = rvalue->symtree->n.sym->result; - name = rvalue->symtree->n.sym->result->name; + name = s2->name; } else { s2 = rvalue->symtree->n.sym; - name = rvalue->symtree->n.sym->name; + name = s2->name; + } + + if (s2->attr.proc_pointer && s2->ts.interface) + s2 = s2->ts.interface; + + if (s1 == s2 || !s1 || !s2) + return SUCCESS; + + if (!gfc_compare_interfaces (s1, s2, name, 0, 1, + err, sizeof(err), NULL, NULL)) + { + gfc_error ("Interface mismatch in procedure pointer assignment " + "at %L: %s", &rvalue->where, err); + return FAILURE; } - if (s1 && s2 && !gfc_compare_interfaces (s1, s2, name, 0, 1, - err, sizeof(err), NULL, NULL)) + if (!gfc_compare_interfaces (s2, s1, name, 0, 1, + err, sizeof(err), NULL, NULL)) { gfc_error ("Interface mismatch in procedure pointer assignment " "at %L: %s", &rvalue->where, err); |