summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-10-04 17:20:36 -0700
committerGitHub <noreply@github.com>2021-10-05 00:20:36 +0000
commit273449dd5be4085eb43592aebaffb483ea995497 (patch)
treef54aedf1fbe87ae166a4e6612bf10afb0d7d4785 /src
parent8895a2417d37e3444c98f0023e98ab9151d04290 (diff)
downloadbinaryen-273449dd5be4085eb43592aebaffb483ea995497.tar.gz
binaryen-273449dd5be4085eb43592aebaffb483ea995497.tar.bz2
binaryen-273449dd5be4085eb43592aebaffb483ea995497.zip
Fix roundtripping specialized element segments of table zero (#4212)
Before this fix, the first table (index 0) is counted as its element segment having "no table index" even when its type is not funcref, which could break things if that table had a more specialized type.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-binary.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index a8eea2808..df7d8c114 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -587,10 +587,15 @@ void WasmBinaryWriter::writeElementSegments() {
// If the segment is MVP, we can use the shorter form.
bool usesExpressions = TableUtils::usesExpressions(segment.get(), wasm);
+ // The table index can and should be elided for active segments of table 0
+ // when table 0 has type funcref. This was the only type of segment
+ // supported by the MVP, which also did not support table indices in the
+ // segment encoding.
bool hasTableIndex = false;
if (!isPassive) {
tableIdx = getTableIndex(segment->table);
- hasTableIndex = tableIdx > 0;
+ hasTableIndex =
+ tableIdx > 0 || wasm->getTable(segment->table)->type != Type::funcref;
}
uint32_t flags = 0;