diff options
author | Alon Zakai <azakai@google.com> | 2021-03-05 20:47:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-05 12:47:01 -0800 |
commit | d7cf703bf9c6c9e09a048b976cfb0c5db6a43270 (patch) | |
tree | 6729e0aa833fcebd346ea18874c90f718fe6bdf1 | |
parent | dfafe354a0ebb6250851399a36b8263dd3d43de3 (diff) | |
download | binaryen-d7cf703bf9c6c9e09a048b976cfb0c5db6a43270.tar.gz binaryen-d7cf703bf9c6c9e09a048b976cfb0c5db6a43270.tar.bz2 binaryen-d7cf703bf9c6c9e09a048b976cfb0c5db6a43270.zip |
[Wasm GC] Fix cost.h on array.new_default (#3658)
-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) + ) + ) +) |