From 52354dadb80b60c3fd05fb1b5aa3feb15a98b8af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20K=C3=B6nig?= Date: Thu, 16 Jan 2020 22:09:37 +0100 Subject: [PATCH] Check for illegal reference in function. --- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/primary.c | 1 + gcc/fortran/resolve.c | 7 +++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gfortran.dg/function_reference_1.f90 | 11 +++++++++++ gcc/testsuite/gfortran.dg/function_reference_2.f90 | 10 ++++++++++ 6 files changed, 42 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/function_reference_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/function_reference_2.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 524ebff3e1f..3f412fd8c20 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2020-01-19 Thomas König + + PR fortran/44960 + * primary.c (gfc_match_rvalue): Break after setting MATCH_ERROR. + * resolve.c (resolve_function): Issue error when a + function call contains a reference. + 2020-01-17 Mark Eggleston PR fortran/93236 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 07b8ac08ba2..bd50827bb15 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -3661,6 +3661,7 @@ gfc_match_rvalue (gfc_expr **result) gfc_error ("The leftmost part-ref in a data-ref cannot be a " "function reference at %C"); m = MATCH_ERROR; + break; } m = MATCH_YES; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index bddab39d023..e840aec62f2 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3129,6 +3129,13 @@ resolve_function (gfc_expr *expr) || sym->intmod_sym_id == GFC_ISYM_CAF_SEND)) return true; + if (expr->ref) + { + gfc_error ("Unexpected junk after %qs at %L", expr->symtree->n.sym->name, + &expr->where); + return false; + } + if (sym && sym->attr.intrinsic && !gfc_resolve_intrinsic (sym, &expr->where)) return false; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aa5505ba261..9066c173bbd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-01-19 Thomas König + + PR fortran/44960 + * gfortran.dg/function_reference_1.f90: New test. + * gfortran.dg/function_reference_2.f90: New test. + 2020-01-18 Jakub Jelinek PR c/92833 diff --git a/gcc/testsuite/gfortran.dg/function_reference_1.f90 b/gcc/testsuite/gfortran.dg/function_reference_1.f90 new file mode 100644 index 00000000000..be634c9dd4b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/function_reference_1.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR 44960 - this was erroneusly accepted. +! Original test case by Daniel Franke. + +type t + integer :: a +end type t +type(t) :: foo +print *, foo(1)%a ! { dg-error "Unexpected junk" } +end + diff --git a/gcc/testsuite/gfortran.dg/function_reference_2.f90 b/gcc/testsuite/gfortran.dg/function_reference_2.f90 new file mode 100644 index 00000000000..375c58bb6d2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/function_reference_2.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR 44960 - improve the error message +program main + type t + integer :: a +end type t +type(t) :: foo +external foo +i = foo(1)%1 ! { dg-error "leftmost part-ref in a data-ref cannot be a function reference" } +end -- 2.30.2