diff options
-rw-r--r-- | src/binary-reader.cc | 1 | ||||
-rw-r--r-- | src/ir.h | 5 | ||||
-rw-r--r-- | test/binary/bad-function-local-count.txt | 16 | ||||
-rw-r--r-- | test/binary/function-local-count-zero.txt | 26 |
4 files changed, 29 insertions, 19 deletions
diff --git a/src/binary-reader.cc b/src/binary-reader.cc index 8b7487a7..ac990f32 100644 --- a/src/binary-reader.cc +++ b/src/binary-reader.cc @@ -2122,7 +2122,6 @@ Result BinaryReader::ReadCodeSection(Offset section_size) { for (Index k = 0; k < num_local_decls; ++k) { Index num_local_types; CHECK_RESULT(ReadIndex(&num_local_types, "local type count")); - ERROR_UNLESS(num_local_types > 0, "local count must be > 0"); total_locals += num_local_types; ERROR_UNLESS(total_locals < UINT32_MAX, "local count must be < 0x10000000"); @@ -466,8 +466,9 @@ class LocalTypes { const Decls& decls() const { return decls_; } void AppendDecl(Type type, Index count) { - assert(count > 0); - decls_.emplace_back(type, count); + if (count != 0) { + decls_.emplace_back(type, count); + } } Index size() const; diff --git a/test/binary/bad-function-local-count.txt b/test/binary/bad-function-local-count.txt deleted file mode 100644 index 7097d203..00000000 --- a/test/binary/bad-function-local-count.txt +++ /dev/null @@ -1,16 +0,0 @@ -;;; TOOL: run-gen-wasm-bad -magic -version -section(TYPE) { count[1] function params[0] results[0] } -section(FUNCTION) { count[1] sig[0] } -section(CODE) { - count[1] - func { - local_decls[1] - locals[0] i32 - } -} -(;; STDERR ;;; -0000018: error: local count must be > 0 -0000018: error: local count must be > 0 -;;; STDERR ;;) diff --git a/test/binary/function-local-count-zero.txt b/test/binary/function-local-count-zero.txt new file mode 100644 index 00000000..f70a50f6 --- /dev/null +++ b/test/binary/function-local-count-zero.txt @@ -0,0 +1,26 @@ +;;; TOOL: run-gen-wasm +magic +version +section(TYPE) { count[1] function params[0] results[0] } +section(FUNCTION) { count[2] sig[0] sig[0] } +section(CODE) { + count[2] + func { + local_decls[1] + locals[0] i32 + } + func { + local_decls[4] + locals[1] i64 + locals[0] i32 + locals[2] f64 + locals[0] f32 + } +} +(;; STDOUT ;;; +(module + (type (;0;) (func)) + (func (;0;) (type 0)) + (func (;1;) (type 0) + (local i64 f64 f64))) +;;; STDOUT ;;) |