summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-03-31 10:48:43 -0700
committerGitHub <noreply@github.com>2022-03-31 10:48:43 -0700
commit33fe4f12bd30739790da3d34f5fae844f47a327f (patch)
tree5c131f3bc288b3f637255628a4f476946245eb57 /src/wasm/wasm-binary.cpp
parent1d24b83eaf710510c132091db89715607d64eea7 (diff)
downloadbinaryen-33fe4f12bd30739790da3d34f5fae844f47a327f.tar.gz
binaryen-33fe4f12bd30739790da3d34f5fae844f47a327f.tar.bz2
binaryen-33fe4f12bd30739790da3d34f5fae844f47a327f.zip
[Wasm GC] Fix stacky non-nullable tuples (#4561)
#4555 fixed validation for such tuples, but we also did not handle them in "stacky" code using pops etc., due to a logic bug in the binary reading code.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index f43346fdb..b67fe013b 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2656,24 +2656,25 @@ void WasmBinaryBuilder::pushExpression(Expression* curr) {
// Store tuple to local and push individual extracted values
Builder builder(wasm);
// Non-nullable types require special handling as they cannot be stored to
- // a local.
- std::vector<Type> finalTypes;
+ // a local, so we may need to use a different local type than the original.
+ auto localType = type;
if (!wasm.features.hasGCNNLocals()) {
+ std::vector<Type> finalTypes;
for (auto t : type) {
if (t.isNonNullable()) {
t = Type(t.getHeapType(), Nullable);
}
finalTypes.push_back(t);
}
+ localType = Type(Tuple(finalTypes));
}
- auto nullableType = Type(Tuple(finalTypes));
requireFunctionContext("pushExpression-tuple");
- Index tuple = builder.addVar(currFunction, nullableType);
+ Index tuple = builder.addVar(currFunction, localType);
expressionStack.push_back(builder.makeLocalSet(tuple, curr));
- for (Index i = 0; i < nullableType.size(); ++i) {
+ for (Index i = 0; i < localType.size(); ++i) {
Expression* value =
- builder.makeTupleExtract(builder.makeLocalGet(tuple, nullableType), i);
- if (nullableType[i] != type[i]) {
+ builder.makeTupleExtract(builder.makeLocalGet(tuple, localType), i);
+ if (localType[i] != type[i]) {
// We modified this to be nullable; undo that.
value = builder.makeRefAs(RefAsNonNull, value);
}