From: Thomas König Date: Thu, 16 Jan 2020 21:09:37 +0000 (+0100) Subject: Check for illegal reference in function. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=52354dadb80b60c3fd05fb1b5aa3feb15a98b8af;p=gcc.git Check for illegal reference in function. --- 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