public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4851] Fortran: check for invalid uses of statement functions arguments [PR69604] Date: Thu, 22 Dec 2022 22:05:30 +0000 (GMT) [thread overview] Message-ID: <20221222220530.E39303858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:794af0d00b7086c9f0493f3a1aaac644e1fd50f6 commit r13-4851-g794af0d00b7086c9f0493f3a1aaac644e1fd50f6 Author: Harald Anlauf <anlauf@gmx.de> Date: Thu Dec 22 22:03:31 2022 +0100 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. Diff: --- gcc/fortran/match.cc | 27 ++++++++++++++++++++++ gcc/testsuite/gfortran.dg/statement_function_4.f90 | 10 ++++++++ 2 files changed, 37 insertions(+) diff --git a/gcc/fortran/match.cc b/gcc/fortran/match.cc index 89fb115c0f6..3d346788416 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 diff --git a/gcc/testsuite/gfortran.dg/statement_function_4.f90 b/gcc/testsuite/gfortran.dg/statement_function_4.f90 new file mode 100644 index 00000000000..6ce5951b53a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/statement_function_4.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/69604 +! Contributed by G.Steinmetz + +program p + x(n) = 1 + n(2.0) ! { dg-error "Invalid use of statement function argument" } + y(k) = k() ! { dg-error "Invalid use of statement function argument" } + z(m) = m ! { dg-warning "Statement function" } + print *, x(n) +end
reply other threads:[~2022-12-22 22:05 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20221222220530.E39303858D1E@sourceware.org \ --to=anlauf@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).