Fix Node::ReplaceUses to handle unused nodes.
authormstarzinger@chromium.org <mstarzinger@chromium.org>
Fri, 29 Aug 2014 12:14:52 +0000 (12:14 +0000)
committermstarzinger@chromium.org <mstarzinger@chromium.org>
Fri, 29 Aug 2014 12:14:52 +0000 (12:14 +0000)
R=bmeurer@chromium.org
TEST=cctest/test-node/NodeUseIteratorReplaceNoUses

Review URL: https://codereview.chromium.org/521643002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23519 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/compiler/generic-node-inl.h
test/cctest/compiler/test-node.cc

index e7a8f90f61b0726036df1caddbc23492ff21e9b3..82fd907c16e18811c00b8bf2c2ab3e4d9a5b2903 100644 (file)
@@ -64,12 +64,13 @@ void GenericNode<B, S>::ReplaceUses(GenericNode* replace_to) {
   if (replace_to->last_use_ == NULL) {
     DCHECK_EQ(NULL, replace_to->first_use_);
     replace_to->first_use_ = first_use_;
-  } else {
+    replace_to->last_use_ = last_use_;
+  } else if (first_use_ != NULL) {
     DCHECK_NE(NULL, replace_to->first_use_);
     replace_to->last_use_->next = first_use_;
     first_use_->prev = replace_to->last_use_;
+    replace_to->last_use_ = last_use_;
   }
-  replace_to->last_use_ = last_use_;
   replace_to->use_count_ += use_count_;
   use_count_ = 0;
   first_use_ = NULL;
index 6fe8573a2f78b3218ab51bc0b3cfcd47f9dd3e1a..da10d250f92457974403b2955d26cd49abdfd89d 100644 (file)
@@ -118,9 +118,14 @@ TEST(NodeUseIteratorOne) {
 TEST(NodeUseIteratorReplaceNoUses) {
   GraphTester graph;
   Node* n0 = graph.NewNode(&dummy_operator);
-  Node* n3 = graph.NewNode(&dummy_operator);
-  n0->ReplaceUses(n3);
+  Node* n1 = graph.NewNode(&dummy_operator);
+  Node* n2 = graph.NewNode(&dummy_operator);
+  Node* n3 = graph.NewNode(&dummy_operator, n2);
+  n0->ReplaceUses(n1);
+  CHECK(n0->uses().begin() == n0->uses().end());
+  n0->ReplaceUses(n2);
   CHECK(n0->uses().begin() == n0->uses().end());
+  USE(n3);
 }