summaryrefslogtreecommitdiff
path: root/test/lit/binary/declarative-element-use-expr.test
diff options
context:
space:
mode:
authorRikito Taniguchi <rikiriki1238@gmail.com>2024-06-04 04:42:02 +0900
committerGitHub <noreply@github.com>2024-06-03 19:42:02 +0000
commit9347a223fcc1b6c297805b3c37fe1e7473158720 (patch)
tree45d356a79b828c5ff948626a7cb7bd1c2654e128 /test/lit/binary/declarative-element-use-expr.test
parent1f2cd4f7b51c7afd6a6cafc4e48286e850bb36bd (diff)
downloadbinaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.tar.gz
binaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.tar.bz2
binaryen-9347a223fcc1b6c297805b3c37fe1e7473158720.zip
Fix binary parser of declarative element segments (#6618)
The parser was incorrectly handling the parsing of declarative element segments whose `init` is a `vec(expr)`. https://webassembly.github.io/spec/core/binary/modules.html#element-section Binry parser was simply reading a single `u32LEB` value for `init` instead of parsing a expression regardless `usesExpressions = true`. This commit updates the `WasmBinaryReader::readElementSegments` function to correctly parse the expressions for declarative element segments by calling `readExpression` instead of `getU32LEB` when `usesExpressions = true`. Resolves the parsing exception: "[parse exception: bad section size, started at ... not being equal to new position ...]" Related discussion: https://github.com/tanishiking/scala-wasm/issues/136
Diffstat (limited to 'test/lit/binary/declarative-element-use-expr.test')
-rw-r--r--test/lit/binary/declarative-element-use-expr.test28
1 files changed, 28 insertions, 0 deletions
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: )