Commit 178c0f5f authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Fix Node::TrimInputCount() followed by Node::AppendInput() bug.

R=mstarzinger@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#28452}
parent 5db7ae47
......@@ -100,7 +100,9 @@ void Node::TrimInputCount(int new_input_count) {
for (int index = new_input_count; index < input_count(); ++index) {
ReplaceInput(index, nullptr);
}
if (!has_appendable_inputs()) {
if (has_appendable_inputs()) {
inputs_.appendable_->resize(new_input_count);
} else {
set_reserved_input_count(std::min<int>(
ReservedInputCountField::kMax,
reserved_input_count() + (input_count() - new_input_count)));
......
......@@ -386,9 +386,7 @@ Node::Inputs::const_iterator Node::Inputs::end() const {
}
// A forward iterator to visit the uses edges of a node. The edges are returned
// in
// the order in which they were added as inputs.
// A forward iterator to visit the uses edges of a node.
class Node::UseEdges::iterator final {
public:
iterator(const iterator& other)
......@@ -433,8 +431,7 @@ Node::UseEdges::iterator Node::UseEdges::end() const {
}
// A forward iterator to visit the uses of a node. The uses are returned in
// the order in which they were added as inputs.
// A forward iterator to visit the uses of a node.
class Node::Uses::const_iterator final {
public:
typedef std::forward_iterator_tag iterator_category;
......
......@@ -166,6 +166,73 @@ TEST_F(NodeTest, AppendInput) {
EXPECT_THAT(node->inputs(), ElementsAre(n0, n1, n0, n0, n1));
}
TEST_F(NodeTest, TrimThenAppend) {
Node* n0 = Node::New(zone(), 0, &kOp0, 0, nullptr, false);
Node* n1 = Node::New(zone(), 1, &kOp0, 0, nullptr, false);
Node* n2 = Node::New(zone(), 2, &kOp0, 0, nullptr, false);
Node* n3 = Node::New(zone(), 3, &kOp0, 0, nullptr, false);
Node* n4 = Node::New(zone(), 4, &kOp0, 0, nullptr, false);
Node* n5 = Node::New(zone(), 5, &kOp0, 0, nullptr, false);
Node* n6 = Node::New(zone(), 6, &kOp0, 0, nullptr, false);
Node* n7 = Node::New(zone(), 7, &kOp0, 0, nullptr, false);
Node* n8 = Node::New(zone(), 8, &kOp0, 0, nullptr, false);
Node* n9 = Node::New(zone(), 9, &kOp0, 0, nullptr, false);
Node* node = Node::New(zone(), 12345, &kOp0, 0, nullptr, true);
EXPECT_TRUE(node->inputs().empty());
node->AppendInput(zone(), n0);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n0));
node->TrimInputCount(0);
EXPECT_TRUE(node->inputs().empty());
node->AppendInput(zone(), n1);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1));
node->AppendInput(zone(), n2);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n2));
node->TrimInputCount(1);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1));
node->AppendInput(zone(), n3);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3));
node->AppendInput(zone(), n4);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4));
node->AppendInput(zone(), n5);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5));
node->AppendInput(zone(), n6);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5, n6));
node->AppendInput(zone(), n7);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5, n6, n7));
node->TrimInputCount(4);
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5));
node->AppendInput(zone(), n8);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5, n8));
node->AppendInput(zone(), n9);
EXPECT_FALSE(node->inputs().empty());
EXPECT_THAT(node->inputs(), ElementsAre(n1, n3, n4, n5, n8, n9));
}
} // namespace compiler
} // namespace internal
} // namespace v8
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