diff options
author | Harald Anlauf <anlauf@gmx.de> | 2022-12-22 22:03:31 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2022-12-22 22:03:31 +0100 |
commit | 794af0d00b7086c9f0493f3a1aaac644e1fd50f6 (patch) | |
tree | e8215bc4ae259fa3813ecb2163e33779860e4a0e /gcc/fortran | |
parent | 74544bdadc44edcd8d55792972e35b2cc07515a4 (diff) | |
download | gcc-794af0d00b7086c9f0493f3a1aaac644e1fd50f6.zip gcc-794af0d00b7086c9f0493f3a1aaac644e1fd50f6.tar.gz gcc-794af0d00b7086c9f0493f3a1aaac644e1fd50f6.tar.bz2 |
Fortran: check for invalid uses of statement functions arguments [PR69604]
gcc/fortran/ChangeLog:
PR fortran/69604
* match.cc (chk_stmt_fcn_body): New function. Check for invalid uses
of statement functions arguments.
(gfc_match_st_function): Use above.
gcc/testsuite/ChangeLog:
PR fortran/69604
* gfortran.dg/statement_function_4.f90: New test.
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/match.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 89fb115..3d34678 100644 --- a/gcc/fortran/match.cc +++ b/gcc/fortran/match.cc @@ -5915,6 +5915,30 @@ recursive_stmt_fcn (gfc_expr *e, gfc_symbol *sym) } +/* Check for invalid uses of statement function dummy arguments in body. */ + +static bool +chk_stmt_fcn_body (gfc_expr *e, gfc_symbol *sym, int *f ATTRIBUTE_UNUSED) +{ + gfc_formal_arglist *formal; + + if (e == NULL || e->symtree == NULL || e->expr_type != EXPR_FUNCTION) + return false; + + for (formal = sym->formal; formal; formal = formal->next) + { + if (formal->sym == e->symtree->n.sym) + { + gfc_error ("Invalid use of statement function argument at %L", + &e->where); + return true; + } + } + + return false; +} + + /* Match a statement function declaration. It is so easy to match non-statement function statements with a MATCH_ERROR as opposed to MATCH_NO that we suppress error message in most cases. */ @@ -5983,6 +6007,9 @@ gfc_match_st_function (void) return MATCH_ERROR; } + if (gfc_traverse_expr (expr, sym, chk_stmt_fcn_body, 0)) + return MATCH_ERROR; + sym->value = expr; if ((gfc_current_state () == COMP_FUNCTION |