public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix capture parsing in (match ...
@ 2014-12-16 14:57 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2014-12-16 14:57 UTC (permalink / raw)
  To: gcc-patches; +Cc: Prathamesh Kulkarni


I am testing the following patch to properly setup capture_ids for
parsing (match ...

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2014-12-16  Richard Biener  <rguenther@suse.de>

	* genmatch.c (parser::parser): Initialize capture_ids.
	(parser::parse_pattern): Properly allocate capture_ids before
	using them.  Set capture_ids to zero when its lifetime is
	supposed to finish.
	(parser::parse_simplify): Allocate capture_ids only if
	required.

Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c	(revision 218747)
+++ gcc/genmatch.c	(working copy)
@@ -3176,7 +3176,8 @@ parser::parse_simplify (source_location
 			expr *result)
 {
   /* Reset the capture map.  */
-  capture_ids = new cid_map_t;
+  if (!capture_ids)
+    capture_ids = new cid_map_t;
   /* Reset oper_lists and set.  */
   hash_set <user_id *> olist;
   oper_lists_set = &olist;
@@ -3494,7 +3495,10 @@ parser::parse_pattern ()
   const cpp_token *token = peek ();
   const char *id = get_ident ();
   if (strcmp (id, "simplify") == 0)
-    parse_simplify (token->src_loc, simplifiers, NULL, NULL);
+    {
+      parse_simplify (token->src_loc, simplifiers, NULL, NULL);
+      capture_ids = NULL;
+    }
   else if (strcmp (id, "match") == 0)
     {
       bool with_args = false;
@@ -3519,6 +3523,7 @@ parser::parse_pattern ()
       expr *e = NULL;
       if (with_args)
 	{
+	  capture_ids = new cid_map_t;
 	  e = new expr (p);
 	  while (peek ()->type == CPP_ATSIGN)
 	    e->append_op (parse_capture (NULL));
@@ -3530,6 +3535,7 @@ parser::parse_pattern ()
 	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);
+      capture_ids = NULL;
     }
   else if (strcmp (id, "for") == 0)
     parse_for (token->src_loc);
@@ -3567,6 +3573,7 @@ parser::parser (cpp_reader *r_)
   simplifiers = vNULL;
   oper_lists_set = NULL;
   oper_lists = vNULL;
+  capture_ids = NULL;
   user_predicates = vNULL;
   parsing_match_operand = false;
 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-12-16 14:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-16 14:57 Fix capture parsing in (match Richard Biener

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).