diff options
-rw-r--r-- | src/ir/cost.h | 2 | ||||
-rw-r--r-- | test/passes/remove-unused-brs_all-features.txt | 18 | ||||
-rw-r--r-- | test/passes/remove-unused-brs_all-features.wast | 19 |
3 files changed, 38 insertions, 1 deletions
diff --git a/src/ir/cost.h b/src/ir/cost.h index 50941bdd3..07219659c 100644 --- a/src/ir/cost.h +++ b/src/ir/cost.h @@ -615,7 +615,7 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, Index> { return 2 + nullCheckCost(curr->ref) + visit(curr->ref) + visit(curr->value); } Index visitArrayNew(ArrayNew* curr) { - return 4 + visit(curr->rtt) + visit(curr->size) + visit(curr->init); + return 4 + visit(curr->rtt) + visit(curr->size) + maybeVisit(curr->init); } Index visitArrayGet(ArrayGet* curr) { return 1 + nullCheckCost(curr->ref) + visit(curr->ref) + visit(curr->index); diff --git a/test/passes/remove-unused-brs_all-features.txt b/test/passes/remove-unused-brs_all-features.txt new file mode 100644 index 000000000..4bf1cfb33 --- /dev/null +++ b/test/passes/remove-unused-brs_all-features.txt @@ -0,0 +1,18 @@ +(module + (type $struct (struct (field (ref null $vector)))) + (type $vector (array (mut i32))) + (type $none_=>_ref?|$struct| (func (result (ref null $struct)))) + (func $foo (result (ref null $struct)) + (if (result (ref null $struct)) + (i32.const 1) + (struct.new_with_rtt $struct + (array.new_default_with_rtt $vector + (i32.const 1) + (rtt.canon $vector) + ) + (rtt.canon $struct) + ) + (ref.null $struct) + ) + ) +) diff --git a/test/passes/remove-unused-brs_all-features.wast b/test/passes/remove-unused-brs_all-features.wast new file mode 100644 index 000000000..4d1a337c6 --- /dev/null +++ b/test/passes/remove-unused-brs_all-features.wast @@ -0,0 +1,19 @@ +(module + (type $vector (array (mut i32))) + (type $struct (struct (field (ref null $vector)))) + (func $foo (result (ref null $struct)) + (if (result (ref null $struct)) + (i32.const 1) + (struct.new_with_rtt $struct + ;; regression test for computing the cost of an array.new_default, which + ;; lacks the optional field "init" + (array.new_default_with_rtt $vector + (i32.const 1) + (rtt.canon $vector) + ) + (rtt.canon $struct) + ) + (ref.null $struct) + ) + ) +) |