This patch rejects 't' outside user-defined predicates.

2014-12-16  Prathamesh Kulkarni  <prathamesh.kulka...@linaro.org>

        * genmatch.c (parser::parsing_match): New.
        (parser::parser): Initialize parsing_match to false.
        (parser::parse_pattern): Reset parsing_match when parsing
user-defined                       predicate.
        (parser::parse_c_expr): Check if 't' is used when parsing_match is set.

Thanks,
Prathamesh
Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c      (revision 218778)
+++ gcc/genmatch.c      (working copy)
@@ -2746,6 +2746,7 @@
   vec<simplify *> simplifiers;
   vec<predicate_id *> user_predicates;
   bool parsing_match_operand;
+  bool parsing_match;
 };
 
 /* Lexing helpers.  */
@@ -3059,8 +3060,11 @@
       /* 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 *lexeme = (const char *) CPP_HASHNODE 
(token->val.node.node)->ident.str;
+         if (strcmp (lexeme, "t") == 0 && !parsing_match)
+           fatal_at (token, "'t' is allowed only in predicates");
+
+         id_base *idb = get_operator (lexeme);
          user_id *p;
          if (idb && (p = dyn_cast<user_id *> (idb)) && p->is_oper_list)
            record_operlist (token->src_loc, p);
@@ -3497,6 +3501,7 @@
     parse_simplify (token->src_loc, simplifiers, NULL, NULL);
   else if (strcmp (id, "match") == 0)
     {
+      parsing_match = true;
       bool with_args = false;
       if (peek ()->type == CPP_OPEN_PAREN)
        {
@@ -3530,6 +3535,7 @@
        fatal_at (token, "non-matching number of match operands");
       p->nargs = e ? e->ops.length () : 0;
       parse_simplify (token->src_loc, p->matchers, p, e);
+      parsing_match = false;
     }
   else if (strcmp (id, "for") == 0)
     parse_for (token->src_loc);
@@ -3569,6 +3575,7 @@
   oper_lists = vNULL;
   user_predicates = vNULL;
   parsing_match_operand = false;
+  parsing_match = false;
 
   const cpp_token *token = next ();
   while (token->type != CPP_EOF)

Reply via email to