summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-06-16 17:42:35 -0700
committerGitHub <noreply@github.com>2022-06-17 00:42:35 +0000
commit4652398b62ce0546f015cdc2c7b3010938c7c5a9 (patch)
tree3abe503a08640c621c98ab8838f972ab03fd862b
parent4a4c9eb87a5e26a86c048529ae19c1f539f949d7 (diff)
downloadbinaryen-4652398b62ce0546f015cdc2c7b3010938c7c5a9.tar.gz
binaryen-4652398b62ce0546f015cdc2c7b3010938c7c5a9.tar.bz2
binaryen-4652398b62ce0546f015cdc2c7b3010938c7c5a9.zip
Fix table exporting (#4736)
This code was apparently not updated when we added multi-table support, and still had the old hardcoded index 0. Fixes #4711
-rw-r--r--src/wasm/wasm-binary.cpp3
-rw-r--r--test/lit/table-multi-export.wast20
2 files changed, 22 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index decd78852..6cbf880e3 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -492,9 +492,10 @@ void WasmBinaryWriter::writeExports() {
o << U32LEB(getFunctionIndex(curr->value));
break;
case ExternalKind::Table:
- o << U32LEB(0);
+ o << U32LEB(getTableIndex(curr->value));
break;
case ExternalKind::Memory:
+ // TODO: fix with multi-memory
o << U32LEB(0);
break;
case ExternalKind::Global:
diff --git a/test/lit/table-multi-export.wast b/test/lit/table-multi-export.wast
new file mode 100644
index 000000000..fd3cc1f7f
--- /dev/null
+++ b/test/lit/table-multi-export.wast
@@ -0,0 +1,20 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: wasm-opt %s -all --roundtrip --print | filecheck %s
+
+;; Test that we properly read and write table exports in the binary format.
+(module
+ ;; Two different tables, each exported.
+
+ ;; CHECK: (table $0 25 25 funcref)
+ (table $0 25 25 funcref)
+ ;; CHECK: (table $1 32 anyref)
+ (table $1 32 anyref)
+
+ ;; Each export should export the right table.
+
+ ;; CHECK: (export "table0" (table $0))
+ (export "table0" (table $0))
+ ;; CHECK: (export "table1" (table $1))
+ (export "table1" (table $1))
+)