summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp6
-rw-r--r--test/lit/binary/declarative-element-use-expr.test28
-rw-r--r--test/lit/binary/declarative-element-use-expr.test.wasmbin0 -> 59 bytes
3 files changed, 33 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 805af1892..32dcc883a 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -3369,7 +3369,11 @@ void WasmBinaryReader::readElementSegments() {
[[maybe_unused]] auto type = getU32LEB();
auto num = getU32LEB();
for (Index i = 0; i < num; i++) {
- getU32LEB();
+ if (usesExpressions) {
+ readExpression();
+ } else {
+ getU32LEB();
+ }
}
continue;
}
diff --git a/test/lit/binary/declarative-element-use-expr.test b/test/lit/binary/declarative-element-use-expr.test
new file mode 100644
index 000000000..aecdf9ebd
--- /dev/null
+++ b/test/lit/binary/declarative-element-use-expr.test
@@ -0,0 +1,28 @@
+;; Verify a binary with declarative element segment whose init is vector of expr
+;; can be parsed correctly.
+;; The declarative-element-use-expr file contains this:
+;;
+;; (module
+;; (type $0 (func))
+;; (func $0 (type 0) (block (ref.func 0) (drop)))
+;; (elem $0 declare funcref (item ref.func 0))
+;; )
+;;
+;; The wasm-opt output contains `(elem declare func 0)` instead of
+;; `(elem declare funcref (item ref.func 0))` because the parser doesn't
+;; preserve declarative segments. This is fine, as we test that the
+;; binary parser can parse it correctly.
+
+;; RUN: wasm-opt -all %s.wasm -all --print | filecheck %s
+
+;; CHECK: (module
+;; CHECK-NEXT: (type $0 (func))
+;; CHECK-NEXT: (elem declare func $0)
+;; CHECK-NEXT: (func $0 (type $0)
+;; CHECK-NEXT: (block $label$1
+;; CHECK-NEXT: (drop
+;; CHECK-NEXT: (ref.func $0)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
diff --git a/test/lit/binary/declarative-element-use-expr.test.wasm b/test/lit/binary/declarative-element-use-expr.test.wasm
new file mode 100644
index 000000000..54ebc37d4
--- /dev/null
+++ b/test/lit/binary/declarative-element-use-expr.test.wasm
Binary files differ