aboutsummaryrefslogtreecommitdiff
path: root/gcc/genmatch.cc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2022-10-13 12:59:09 +0200
committerRichard Biener <rguenther@suse.de>2022-10-13 13:48:54 +0200
commit786e4c024f941671a233f5779d73a5d22f4e9588 (patch)
tree53acf5ed89d025c51d9961c64f2451a4d9071af4 /gcc/genmatch.cc
parent9f0d4adabe2035886a1aa8d2ca990a90de000613 (diff)
downloadgcc-786e4c024f941671a233f5779d73a5d22f4e9588.zip
gcc-786e4c024f941671a233f5779d73a5d22f4e9588.tar.gz
gcc-786e4c024f941671a233f5779d73a5d22f4e9588.tar.bz2
diagnose return statement in match.pd (with { ... } expressions
The expression in (with { ... } is used like a statement expression which means control flow that leaves it is not allowed. The following explicitely diagnoses 'return' and fixes up the few cases that crept into match.pd (oops). Any such return will prematurely end matching the current expression. * genmatch.cc (parser::parse_c_expr): Diagnose 'return'. * match.pd: Replace 'return' statements in with expressions with appropriate variants.
Diffstat (limited to 'gcc/genmatch.cc')
-rw-r--r--gcc/genmatch.cc7
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc
index a0b22c5..4a88024 100644
--- a/gcc/genmatch.cc
+++ b/gcc/genmatch.cc
@@ -4447,8 +4447,11 @@ parser::parse_c_expr (cpp_ttype start)
/* If this is possibly a user-defined identifier mark it used. */
if (token->type == CPP_NAME)
{
- id_base *idb = get_operator ((const char *)CPP_HASHNODE
- (token->val.node.node)->ident.str);
+ const char *str
+ = (const char *)CPP_HASHNODE (token->val.node.node)->ident.str;
+ if (strcmp (str, "return") == 0)
+ fatal_at (token, "return statement not allowed in C expression");
+ id_base *idb = get_operator (str);
user_id *p;
if (idb && (p = dyn_cast<user_id *> (idb)) && p->is_oper_list)
record_operlist (token->src_loc, p);