summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-09-02 09:17:37 -0700
committerGitHub <noreply@github.com>2021-09-02 09:17:37 -0700
commite84980dffb62d672c991960a701a3c7de8f8aa74 (patch)
tree8e130330f04c3cf10702bc24241061f33591b2f9 /src/wasm/wasm-binary.cpp
parent4bf2d3bc3da17a28b65222d6e84f6126dcb9c553 (diff)
downloadbinaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.gz
binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.tar.bz2
binaryen-e84980dffb62d672c991960a701a3c7de8f8aa74.zip
Support specialized function types in element segments (#4109)
Before this, the element segments would be printed as having type funcref, and then if their table had a specialized type, the element type would not be a subtype of the table and validation would fail.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index ab229f111..ee3c1a6fa 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -584,11 +584,8 @@ void WasmBinaryWriter::writeElementSegments() {
Index tableIdx = 0;
bool isPassive = segment->table.isNull();
- // if all items are ref.func, we can use the shorter form.
- bool usesExpressions =
- std::any_of(segment->data.begin(),
- segment->data.end(),
- [](Expression* curr) { return !curr->is<RefFunc>(); });
+ // If the segment is MVP, we can use the shorter form.
+ bool usesExpressions = TableUtils::usesExpressions(segment.get(), wasm);
bool hasTableIndex = false;
if (!isPassive) {
@@ -620,7 +617,7 @@ void WasmBinaryWriter::writeElementSegments() {
// elemType
writeType(segment->type);
} else {
- // elemKind funcref
+ // MVP elemKind of funcref
o << U32LEB(0);
}
}
@@ -2864,12 +2861,12 @@ void WasmBinaryBuilder::readElementSegments() {
if (usesExpressions) {
segment->type = getType();
if (!segment->type.isFunction()) {
- throwError("Invalid type for an element segment");
+ throwError("Invalid type for a usesExpressions element segment");
}
} else {
auto elemKind = getU32LEB();
if (elemKind != 0x0) {
- throwError("Only funcref elem kinds are valid.");
+ throwError("Invalid kind (!= funcref(0)) since !usesExpressions.");
}
}
}