summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/passes/Print.cpp1
-rw-r--r--src/passes/TupleOptimization.cpp2
-rw-r--r--src/wasm/wasm-s-parser.cpp15
3 files changed, 12 insertions, 6 deletions
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index 51909c6ff..3feebd121 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -1998,6 +1998,7 @@ struct PrintExpressionContents
}
void visitTupleExtract(TupleExtract* curr) {
printMedium(o, "tuple.extract ");
+ o << curr->tuple->type.size() << " ";
o << curr->index;
}
void visitRefI31(RefI31* curr) { printMedium(o, "ref.i31"); }
diff --git a/src/passes/TupleOptimization.cpp b/src/passes/TupleOptimization.cpp
index 16a2bad58..25da1c5ec 100644
--- a/src/passes/TupleOptimization.cpp
+++ b/src/passes/TupleOptimization.cpp
@@ -22,7 +22,7 @@
// (local.set $tuple
// (tuple.make 3 (A) (B) (C)))
// (use
-// (tuple.extract 0
+// (tuple.extract 3 0
// (local.get $tuple)))
//
// If there are no other uses, then we just need one of the three lanes. By
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp
index 521060749..94b434dfb 100644
--- a/src/wasm/wasm-s-parser.cpp
+++ b/src/wasm/wasm-s-parser.cpp
@@ -2872,11 +2872,16 @@ Expression* SExpressionWasmBuilder::makeTupleMake(Element& s) {
Expression* SExpressionWasmBuilder::makeTupleExtract(Element& s) {
auto ret = allocator.alloc<TupleExtract>();
- ret->index = parseIndex(*s[1]);
- ret->tuple = parseExpression(s[2]);
- if (ret->tuple->type != Type::unreachable &&
- ret->index >= ret->tuple->type.size()) {
- throw SParseException("Bad index on tuple.extract", s, *s[1]);
+ size_t arity = std::stoll(s[1]->toString());
+ ret->index = parseIndex(*s[2]);
+ ret->tuple = parseExpression(s[3]);
+ if (ret->tuple->type != Type::unreachable) {
+ if (arity != ret->tuple->type.size()) {
+ throw SParseException("Unexpected tuple.extract arity", s, *s[1]);
+ }
+ if (ret->index >= ret->tuple->type.size()) {
+ throw SParseException("Bad index on tuple.extract", s, *s[2]);
+ }
}
ret->finalize();
return ret;