summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-04-11 12:10:10 -0700
committerGitHub <noreply@github.com>2024-04-11 19:10:10 +0000
commitda8b071ba8c5cd290853188a6b7704417ca254eb (patch)
tree0f0c61b5257c2b4bc6ed91d4be6467d3a3c0ba8d
parentadea6e0f80c68108691f28ab4aa81b8f8973ac35 (diff)
downloadbinaryen-da8b071ba8c5cd290853188a6b7704417ca254eb.tar.gz
binaryen-da8b071ba8c5cd290853188a6b7704417ca254eb.tar.bz2
binaryen-da8b071ba8c5cd290853188a6b7704417ca254eb.zip
[Parser] Use unreachables to fulfill tuple requirements (#6488)
When we need to pop a tuple and the top value on the stack is unreachable, just pop the unreachable rather than producing a tuple.make. This always produces valid IR since an unreachable is always valid where a tuple would otherwise be expected. It also avoids bloating the parsed IR, since we would previously parse a `tuple.make` where all the children were unreachable in this case.
-rw-r--r--src/wasm/wasm-ir-builder.cpp4
-rw-r--r--test/lit/wat-kitchen-sink.wast5
2 files changed, 4 insertions, 5 deletions
diff --git a/src/wasm/wasm-ir-builder.cpp b/src/wasm/wasm-ir-builder.cpp
index 99462e9a8..7b88d345f 100644
--- a/src/wasm/wasm-ir-builder.cpp
+++ b/src/wasm/wasm-ir-builder.cpp
@@ -175,7 +175,9 @@ Result<Expression*> IRBuilder::pop(size_t size) {
CHECK_ERR(packageHoistedValue(*hoisted, size));
auto* ret = scope.exprStack.back();
- if (ret->type.size() == size) {
+ // If the top value has the correct size, we can pop it and be done.
+ // Unreachable values satisfy any size.
+ if (ret->type.size() == size || ret->type == Type::unreachable) {
scope.exprStack.pop_back();
return ret;
}
diff --git a/test/lit/wat-kitchen-sink.wast b/test/lit/wat-kitchen-sink.wast
index e67d3f438..10c58b603 100644
--- a/test/lit/wat-kitchen-sink.wast
+++ b/test/lit/wat-kitchen-sink.wast
@@ -3652,10 +3652,7 @@
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: (return
- ;; CHECK-NEXT: (tuple.make 2
- ;; CHECK-NEXT: (unreachable)
- ;; CHECK-NEXT: (unreachable)
- ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $return-two-second-unreachable (param i32) (result i32 i64)