public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-860] c/100522 - avoid invalid GIMPLE in GIMPLE parsing Date: Tue, 18 May 2021 07:53:46 +0000 (GMT) [thread overview] Message-ID: <20210518075346.8215B394341B@sourceware.org> (raw) https://gcc.gnu.org/g:414fe08a352eac69168f4fb3671246c84a1ac5aa commit r12-860-g414fe08a352eac69168f4fb3671246c84a1ac5aa Author: Richard Biener <rguenther@suse.de> Date: Tue May 18 08:41:43 2021 +0200 c/100522 - avoid invalid GIMPLE in GIMPLE parsing This plugs a few easy holes avoiding ICEs down the route. 2021-05-18 Richard Biener <rguenther@suse.de> PR c/100522 gcc/c/ * gimple-parser.c (c_parser_gimple_postfix_expression_after_primary): Diagnose calls to non-functions. (c_parser_gimple_statement): Diagnose unexpected assignment RHS. gcc/testsuite/ * gcc.dg/gimplefe-error-10.c: New testcase. Diff: --- gcc/c/gimple-parser.c | 11 +++++++++++ gcc/testsuite/gcc.dg/gimplefe-error-10.c | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 398e21631d9..dfacf23c40a 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -877,6 +877,11 @@ c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq) rhs.value = build3_loc (loc, COND_EXPR, TREE_TYPE (trueval.value), rhs.value, trueval.value, falseval.value); } + if (get_gimple_rhs_class (TREE_CODE (rhs.value)) == GIMPLE_INVALID_RHS) + { + c_parser_error (parser, "unexpected RHS for assignment"); + return; + } assign = gimple_build_assign (lhs.value, rhs.value); gimple_seq_add_stmt_without_update (seq, assign); gimple_set_location (assign, loc); @@ -1754,6 +1759,12 @@ c_parser_gimple_postfix_expression_after_primary (gimple_parser &parser, c_parser_gimple_expr_list (parser, &exprlist); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); + if (!FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr.value))) + { + c_parser_error (parser, "invalid call to non-function"); + expr.set_error (); + break; + } expr.value = build_call_array_loc (expr_loc, TREE_TYPE (TREE_TYPE (expr.value)), expr.value, exprlist.length (), exprlist.address ()); diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-10.c b/gcc/testsuite/gcc.dg/gimplefe-error-10.c new file mode 100644 index 00000000000..13d86ac5d1d --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-10.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +__GIMPLE +void foo() { + int t1; + t1_1 = t1_1(); /* { dg-error "invalid call" } */ +}
reply other threads:[~2021-05-18 7:53 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=20210518075346.8215B394341B@sourceware.org \ --to=rguenth@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).