From 67c0e9f5bd66940bf0340b8f0bd0c0c81f11854d Mon Sep 17 00:00:00 2001 From: pault Date: Thu, 9 Nov 2017 19:12:41 +0000 Subject: [PATCH] 2017-11-09 Paul Thomas PR fortran/78619 * check.c (same_type_check): Introduce a new argument 'assoc' with default value false. If this is true, use the symbol type spec of BT_PROCEDURE expressions. (gfc_check_associated): Set 'assoc' true in the call to 'same_type_check'. 2017-11-09 Paul Thomas PR fortran/78619 * gfortran.dg/pr78619.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@254605 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 9 +++++++++ gcc/fortran/check.c | 19 +++++++++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/pr78619.f90 | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr78619.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 9be20c889a1..7d016278b26 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2017-11-09 Paul Thomas + + PR fortran/78619 + * check.c (same_type_check): Introduce a new argument 'assoc' + with default value false. If this is true, use the symbol type + spec of BT_PROCEDURE expressions. + (gfc_check_associated): Set 'assoc' true in the call to + 'same_type_check'. + 2017-11-09 Steven G. Kargl PR fortran/78814 diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c index 914dbf957fd..a147449bf70 100644 --- a/gcc/fortran/check.c +++ b/gcc/fortran/check.c @@ -427,15 +427,22 @@ less_than_bitsize2 (const char *arg1, gfc_expr *expr1, const char *arg2, /* Make sure two expressions have the same type. */ static bool -same_type_check (gfc_expr *e, int n, gfc_expr *f, int m) +same_type_check (gfc_expr *e, int n, gfc_expr *f, int m, bool assoc = false) { gfc_typespec *ets = &e->ts; gfc_typespec *fts = &f->ts; - if (e->ts.type == BT_PROCEDURE && e->symtree->n.sym) - ets = &e->symtree->n.sym->ts; - if (f->ts.type == BT_PROCEDURE && f->symtree->n.sym) - fts = &f->symtree->n.sym->ts; + if (assoc) + { + /* Procedure pointer component expressions have the type of the interface + procedure. If they are being tested for association with a procedure + pointer (ie. not a component), the type of the procedure must be + determined. */ + if (e->ts.type == BT_PROCEDURE && e->symtree->n.sym) + ets = &e->symtree->n.sym->ts; + if (f->ts.type == BT_PROCEDURE && f->symtree->n.sym) + fts = &f->symtree->n.sym->ts; + } if (gfc_compare_types (ets, fts)) return true; @@ -1002,7 +1009,7 @@ gfc_check_associated (gfc_expr *pointer, gfc_expr *target) } t = true; - if (!same_type_check (pointer, 0, target, 1)) + if (!same_type_check (pointer, 0, target, 1, true)) t = false; if (!rank_check (target, 0, pointer->rank)) t = false; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7ee000b07de..17fa7662880 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-09 Paul Thomas + + PR fortran/78619 + * gfortran.dg/pr78619.f90: New test. + 2017-11-09 Steven G. Kargl PR fortran/78814 diff --git a/gcc/testsuite/gfortran.dg/pr78619.f90 b/gcc/testsuite/gfortran.dg/pr78619.f90 new file mode 100644 index 00000000000..5fbe185cfab --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr78619.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! { dg-options "-Werror -O3" } +! +! Tests the fix for PR78619, in which the recursive use of 'f' at line 13 +! caused an ICE. +! +! Contributed by Gerhard Steinmetz +! + print *, g(1.0) ! 'g' is OK +contains + function f(x) result(z) + real :: x, z + z = sign(1.0, f) ! { dg-error "calling itself recursively|must be the same type" } + end + real function g(x) + real :: x + g = -1 + g = -sign(1.0, g) ! This is OK. + end +end +! { dg-message "all warnings being treated as errors" "" { target *-*-* } 0 } -- 2.11.4.GIT