summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Smith <binji@chromium.org>2016-12-15 13:56:06 -0800
committerBen Smith <binji@chromium.org>2016-12-15 15:22:45 -0800
commit8d0fcc1fe04fd3497795a01c692667d7d47f3441 (patch)
tree12cc82b236bc1aa376d60bd9a22ece577dfc10c7 /src
parent180003ae092d1f083a1142fd5966aa5c24664cf8 (diff)
downloadwabt-8d0fcc1fe04fd3497795a01c692667d7d47f3441.tar.gz
wabt-8d0fcc1fe04fd3497795a01c692667d7d47f3441.tar.bz2
wabt-8d0fcc1fe04fd3497795a01c692667d7d47f3441.zip
Update testsuite to f71cbe72bd5f4fb871bee39a9dc1278fa662a8a5
Diffstat (limited to 'src')
-rw-r--r--src/binary-reader-ast.c2
-rw-r--r--src/binary-reader.c10
-rw-r--r--src/tools/wasm2wast.c5
-rw-r--r--src/validator.c13
4 files changed, 23 insertions, 7 deletions
diff --git a/src/binary-reader-ast.c b/src/binary-reader-ast.c
index e82b82c2..68c49be7 100644
--- a/src/binary-reader-ast.c
+++ b/src/binary-reader-ast.c
@@ -1163,5 +1163,7 @@ WasmResult wasm_read_binary_ast(struct WasmAllocator* allocator,
WasmResult result =
wasm_read_binary(allocator, data, size, &reader, 1, options);
WASM_DESTROY_VECTOR_AND_ELEMENTS(allocator, ctx.label_stack, label_node);
+ if (WASM_FAILED(result))
+ wasm_destroy_module(allocator, out_module);
return result;
}
diff --git a/src/binary-reader.c b/src/binary-reader.c
index a9927c13..d32bfc1f 100644
--- a/src/binary-reader.c
+++ b/src/binary-reader.c
@@ -1914,7 +1914,7 @@ WasmResult wasm_read_binary(WasmAllocator* allocator,
CALLBACK_SECTION(begin_memory_section);
uint32_t i;
in_u32_leb128(ctx, &ctx->num_memories, "memory count");
- RAISE_ERROR_UNLESS(ctx->num_memories, "memory count must be 0 or 1");
+ RAISE_ERROR_UNLESS(ctx->num_memories <= 1, "memory count must be 0 or 1");
CALLBACK(on_memory_count, ctx->num_memories);
for (i = 0; i < ctx->num_memories; ++i) {
WasmLimits page_limits;
@@ -1999,12 +1999,12 @@ WasmResult wasm_read_binary(WasmAllocator* allocator,
/* elem */
if (skip_until_section(ctx, WASM_BINARY_SECTION_ELEM, &section_size)) {
- RAISE_ERROR_UNLESS(num_total_tables(ctx) > 0,
- "elem section without table section");
CALLBACK_SECTION(begin_elem_section);
uint32_t i, num_elem_segments;
in_u32_leb128(ctx, &num_elem_segments, "elem segment count");
CALLBACK(on_elem_segment_count, num_elem_segments);
+ RAISE_ERROR_UNLESS(num_elem_segments == 0 || num_total_tables(ctx) > 0,
+ "elem section without table section");
for (i = 0; i < num_elem_segments; ++i) {
uint32_t table_index;
in_u32_leb128(ctx, &table_index, "elem segment table index");
@@ -2073,12 +2073,12 @@ WasmResult wasm_read_binary(WasmAllocator* allocator,
/* data */
if (skip_until_section(ctx, WASM_BINARY_SECTION_DATA, &section_size)) {
- RAISE_ERROR_UNLESS(num_total_memories(ctx) > 0,
- "data section without memory section");
CALLBACK_SECTION(begin_data_section);
uint32_t i, num_data_segments;
in_u32_leb128(ctx, &num_data_segments, "data segment count");
CALLBACK(on_data_segment_count, num_data_segments);
+ RAISE_ERROR_UNLESS(num_data_segments == 0 || num_total_memories(ctx) > 0,
+ "data section without memory section");
for (i = 0; i < num_data_segments; ++i) {
uint32_t memory_index;
in_u32_leb128(ctx, &memory_index, "data segment memory index");
diff --git a/src/tools/wasm2wast.c b/src/tools/wasm2wast.c
index fd94b8ec..55050f96 100644
--- a/src/tools/wasm2wast.c
+++ b/src/tools/wasm2wast.c
@@ -189,10 +189,11 @@ int main(int argc, char** argv) {
wasm_close_file_writer(&file_writer);
}
}
+
+ if (s_use_libc_allocator)
+ wasm_destroy_module(allocator, &module);
}
- if (s_use_libc_allocator)
- wasm_destroy_module(allocator, &module);
wasm_free(allocator, data);
wasm_print_allocator_stats(allocator);
wasm_destroy_allocator(allocator);
diff --git a/src/validator.c b/src/validator.c
index 635dd3ba..79b3316d 100644
--- a/src/validator.c
+++ b/src/validator.c
@@ -565,6 +565,15 @@ static void check_block(Context* ctx,
ctx->type_stack.size = ctx->top_label->type_stack_limit;
}
+static void check_has_memory(Context* ctx,
+ const WasmLocation* loc,
+ WasmOpcode opcode) {
+ if (ctx->current_module->memories.size == 0) {
+ print_error(ctx, loc, "%s requires an imported or defined memory.",
+ wasm_get_opcode_name(opcode));
+ }
+}
+
static void check_expr(Context* ctx, const WasmExpr* expr) {
switch (expr->type) {
case WASM_EXPR_TYPE_BINARY:
@@ -663,6 +672,7 @@ static void check_expr(Context* ctx, const WasmExpr* expr) {
}
case WASM_EXPR_TYPE_GROW_MEMORY:
+ check_has_memory(ctx, &expr->loc, WASM_OPCODE_GROW_MEMORY);
check_opcode1(ctx, &expr->loc, WASM_OPCODE_GROW_MEMORY);
break;
@@ -678,6 +688,7 @@ static void check_expr(Context* ctx, const WasmExpr* expr) {
}
case WASM_EXPR_TYPE_LOAD:
+ check_has_memory(ctx, &expr->loc, expr->load.opcode);
check_align(ctx, &expr->loc, expr->load.align,
get_opcode_natural_alignment(expr->load.opcode));
check_offset(ctx, &expr->loc, expr->load.offset);
@@ -694,6 +705,7 @@ static void check_expr(Context* ctx, const WasmExpr* expr) {
}
case WASM_EXPR_TYPE_CURRENT_MEMORY:
+ check_has_memory(ctx, &expr->loc, WASM_OPCODE_CURRENT_MEMORY);
push_type(ctx, WASM_TYPE_I32);
break;
@@ -739,6 +751,7 @@ static void check_expr(Context* ctx, const WasmExpr* expr) {
}
case WASM_EXPR_TYPE_STORE:
+ check_has_memory(ctx, &expr->loc, expr->store.opcode);
check_align(ctx, &expr->loc, expr->store.align,
get_opcode_natural_alignment(expr->store.opcode));
check_offset(ctx, &expr->loc, expr->store.offset);