Patchwork [pph] Identify and diagnose one class of bad merges (issue5822054)

login
register
mail settings
Submitter Diego Novillo
Date March 14, 2012, 11:49 p.m.
Message ID <20120314234935.A42DFAE1E4@tobiano.tor.corp.google.com>
Download mbox | patch
Permalink /patch/146788/
State New
Headers show

Comments

Diego Novillo - March 14, 2012, 11:49 p.m.
Detect one class of invalid merges.

When merging two different EXPRs, we are currently merging some trees
that should not be merged.  This patch tries to identify one case
where we can certainly detect that a bad merge is about to happen.

This fixes no tests, but diagnoses quite a few bad merges in our
internal testing.  Lawrence will be producing test cases for those.

2012-03-14   Diego Novillo  <dnovillo@google.com>

	* pph-in.c (pph_in_merge_key_tree_with_searcher): Detect and
	diagnose attempts to merge two distinct trees from the same
	PPH image.


--
This patch is available for review at http://codereview.appspot.com/5822054

Patch

diff --git a/gcc/cp/pph-in.c b/gcc/cp/pph-in.c
index a328e13..ba89aa4 100644
--- a/gcc/cp/pph-in.c
+++ b/gcc/cp/pph-in.c
@@ -2625,7 +2625,23 @@  pph_in_merge_key_tree_with_searcher (pph_stream *stream, void *holder,
   gcc_assert (expr != NULL);
 
   if (expr != read_expr)
-    pph_merge_tree_attributes (expr, read_expr);
+    {
+      /* When STREAM was generated, EXPR and READ_EXPR were saved as
+	 distinct trees (otherwise, we would have gotten READ_EXPR as
+	 an internal reference). That's why we are reading them now as
+	 distinct pointers.
+
+	 So, if we find that EXPR has already been registered in
+	 STREAM's cache, it means that we should not be trying to
+	 merge them.  After all, the writer considered them different
+	 objects.  */
+      if (pph_cache_lookup (&stream->cache, expr, NULL,
+			    pph_tree_code_to_tag (expr)))
+	fatal_error ("Trying to merge distinct trees from the same "
+		     "PPH image %s", stream->name);
+
+      pph_merge_tree_attributes (expr, read_expr);
+    }
 
   pph_cache_insert_at (&stream->cache, expr, ix,
 		       pph_tree_code_to_tag (expr));