diff options
-rw-r--r-- | src/interp/binary-reader-interp.cc | 41 | ||||
-rw-r--r-- | test/regress/regress-26.txt | 19 | ||||
-rw-r--r-- | test/regress/regress-27.txt | 19 | ||||
-rw-r--r-- | test/regress/regress-28.txt | 20 |
4 files changed, 97 insertions, 2 deletions
diff --git a/src/interp/binary-reader-interp.cc b/src/interp/binary-reader-interp.cc index 6757f252..d847fa8e 100644 --- a/src/interp/binary-reader-interp.cc +++ b/src/interp/binary-reader-interp.cc @@ -142,6 +142,7 @@ class BinaryReaderInterp : public BinaryReaderNop { wabt::Result OnLocalDeclCount(Index count) override; wabt::Result OnLocalDecl(Index decl_index, Index count, Type type) override; + wabt::Result OnOpcode(Opcode Opcode) override; wabt::Result OnAtomicLoadExpr(Opcode opcode, uint32_t alignment_log2, Address offset) override; @@ -218,6 +219,7 @@ class BinaryReaderInterp : public BinaryReaderNop { Index table_index, bool passive, Type elem_type) override; + wabt::Result BeginElemSegmentInitExpr(Index index) override; wabt::Result EndElemSegmentInitExpr(Index index) override; wabt::Result OnElemSegmentElemExprCount(Index index, Index count) override; wabt::Result OnElemSegmentElemExpr_RefNull(Index segment_index) override; @@ -228,6 +230,7 @@ class BinaryReaderInterp : public BinaryReaderNop { wabt::Result BeginDataSegment(Index index, Index memory_index, bool passive) override; + wabt::Result BeginDataSegmentInitExpr(Index index) override; wabt::Result OnDataSegmentData(Index index, const void* data, Address size) override; @@ -302,6 +305,7 @@ class BinaryReaderInterp : public BinaryReaderNop { wabt::Result CheckAlign(uint32_t alignment_log2, Address natural_alignment); wabt::Result CheckAtomicAlign(uint32_t alignment_log2, Address natural_alignment); + wabt::Result CheckInFunction(); wabt::Result AppendExport(Module* module, ExternalKind kind, @@ -1047,9 +1051,22 @@ wabt::Result BinaryReaderInterp::BeginElemSegment(Index index, return wabt::Result::Ok; } +wabt::Result BinaryReaderInterp::BeginElemSegmentInitExpr(Index index) { + init_expr_value_.type = Type::Void; + return wabt::Result::Ok; +} + wabt::Result BinaryReaderInterp::EndElemSegmentInitExpr(Index index) { assert(segment_is_passive_ == false); - assert(init_expr_value_.type == Type::I32); + + if (init_expr_value_.type != Type::I32) { + PrintError( + "type mismatch in elem segment initializer expression, expected i32 " + "but got %s", + GetTypeName(init_expr_value_.type)); + return wabt::Result::Error; + } + table_offset_ = init_expr_value_.value.i32; return wabt::Result::Ok; } @@ -1114,6 +1131,11 @@ wabt::Result BinaryReaderInterp::BeginDataSegment(Index index, return wabt::Result::Ok; } +wabt::Result BinaryReaderInterp::BeginDataSegmentInitExpr(Index index) { + init_expr_value_.type = Type::Void; + return wabt::Result::Ok; +} + wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index, const void* src_data, Address size) { @@ -1124,6 +1146,14 @@ wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index, memcpy(segment->data.data(), src_data, size); } } else { + if (init_expr_value_.type != Type::I32) { + PrintError( + "type mismatch in data segment initializer expression, expected i32 " + "but got %s", + GetTypeName(init_expr_value_.type)); + return wabt::Result::Error; + } + // An active segment still is present in the segment index space, but // cannot be used with `memory.init` (it's as if it has already been // dropped). @@ -1131,7 +1161,6 @@ wabt::Result BinaryReaderInterp::OnDataSegmentData(Index index, assert(module_->memory_index != kInvalidIndex); Memory* memory = env_->GetMemory(module_->memory_index); - assert(init_expr_value_.type == Type::I32); Address address = init_expr_value_.value.i32; data_segment_infos_.emplace_back(memory, address, src_data, size); } @@ -1251,6 +1280,14 @@ wabt::Result BinaryReaderInterp::CheckAtomicAlign(uint32_t alignment_log2, return wabt::Result::Ok; } +wabt::Result BinaryReaderInterp::OnOpcode(Opcode opcode) { + if (current_func_ == nullptr || label_stack_.size() == 0) { + PrintError("Unexpected instruction after end of function"); + return wabt::Result::Error; + } + return wabt::Result::Ok; +} + wabt::Result BinaryReaderInterp::OnUnaryExpr(wabt::Opcode opcode) { CHECK_RESULT(typechecker_.OnUnary(opcode)); CHECK_RESULT(EmitOpcode(opcode)); diff --git a/test/regress/regress-26.txt b/test/regress/regress-26.txt new file mode 100644 index 00000000..6a76a807 --- /dev/null +++ b/test/regress/regress-26.txt @@ -0,0 +1,19 @@ +;;; TOOL: run-gen-wasm-interp +;;; ERROR: 1 +magic +version +section(TABLE) { + count[1] + anyfunc + has_max[0] + initial[0] +} +section(ELEM) { + count[1] + flags[0] + addr[end] +} +(;; STDERR ;;; +error: type mismatch in elem segment initializer expression, expected i32 but got void +0000013: error: EndElemSegmentInitExpr callback failed +;;; STDERR ;;) diff --git a/test/regress/regress-27.txt b/test/regress/regress-27.txt new file mode 100644 index 00000000..b257407b --- /dev/null +++ b/test/regress/regress-27.txt @@ -0,0 +1,19 @@ +;;; TOOL: run-gen-wasm-interp +;;; ERROR: 1 +magic +version +section(MEMORY) { + count[1] + has_max[0] + initial[0] +} +section(DATA) { + count[1] + flags[0] + addr[end] + data[str("test")] +} +(;; STDERR ;;; +error: type mismatch in data segment initializer expression, expected i32 but got void +0000017: error: OnDataSegmentData callback failed +;;; STDERR ;;) diff --git a/test/regress/regress-28.txt b/test/regress/regress-28.txt new file mode 100644 index 00000000..a065b513 --- /dev/null +++ b/test/regress/regress-28.txt @@ -0,0 +1,20 @@ +;;; TOOL: run-gen-wasm-interp +;;; ERROR: 1 +magic +version +section(TYPE) { count[1] function params[0] results[0] } +section(FUNCTION) { count[1] type[0] } +section(CODE) { + count[1] + func { + locals[0] + unreachable + end + i32.div_s + select + } +} +(;; STDERR ;;; +error: Unexpected instruction after end of function +000001a: error: OnOpcode callback failed +;;; STDERR ;;) |