Fix Node::ReplaceUses to handle unused nodes.

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
parent 5a37d227
......@@ -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;
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment