Hi,
I suppose we should reject duplicate captures used as "arguments" in user
defined predicates ?
eg:
(match (foo @0 @0)
  match-template)
The attached patch prints error "duplicate capture id" for above pattern.
Bootstrapped+tested on x86_64-pc-linux-gnu.
Ok for trunk ?

Thanks,
Prathamesh
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 1f5f45c..eca5508 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -3602,7 +3602,7 @@ private:
   const char *get_number ();
 
   id_base *parse_operation ();
-  operand *parse_capture (operand *, bool);
+  operand *parse_capture (operand *, bool, bool);
   operand *parse_expr ();
   c_expr *parse_c_expr (cpp_ttype);
   operand *parse_op ();
@@ -3832,7 +3832,7 @@ parser::parse_operation ()
      capture = '@'<number>  */
 
 struct operand *
-parser::parse_capture (operand *op, bool require_existing)
+parser::parse_capture (operand *op, bool require_existing, bool 
error_on_existing = false)
 {
   source_location src_loc = eat_token (CPP_ATSIGN)->src_loc;
   const cpp_token *token = peek ();
@@ -3852,6 +3852,8 @@ parser::parse_capture (operand *op, bool require_existing)
        fatal_at (src_loc, "unknown capture id");
       num = next_id;
     }
+  else if (error_on_existing)
+    fatal_at (src_loc, "duplicate capture id");
   return new capture (src_loc, num, op);
 }
 
@@ -4530,7 +4532,7 @@ parser::parse_pattern ()
          capture_ids = new cid_map_t;
          e = new expr (p, e_loc);
          while (peek ()->type == CPP_ATSIGN)
-           e->append_op (parse_capture (NULL, false));
+           e->append_op (parse_capture (NULL, false, true));
          eat_token (CPP_CLOSE_PAREN);
        }
       if (p->nargs != -1

Attachment: ChangeLog
Description: Binary data

Reply via email to