summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm-ast-checker.c78
-rw-r--r--src/wasm-ast-parser.y6
-rw-r--r--test/binary/bad-function-body-size.txt8
-rw-r--r--test/parse/expr/bad-callindirect-too-few-named.txt3
-rw-r--r--test/parse/expr/bad-callindirect-too-few.txt3
-rw-r--r--test/parse/expr/bad-callindirect-too-many-named.txt3
-rw-r--r--test/parse/expr/bad-callindirect-too-many.txt3
-rw-r--r--test/parse/expr/bad-return-multi.txt4
-rw-r--r--test/parse/expr/bad-return-too-many.txt4
-rw-r--r--test/parse/expr/callindirect-named.txt1
-rw-r--r--test/parse/expr/callindirect.txt1
-rw-r--r--test/parse/func/bad-result-empty.txt7
-rw-r--r--test/parse/func/bad-result-multi.txt4
-rw-r--r--test/parse/func/bad-result-type.txt3
-rw-r--r--test/parse/func/result-empty.txt1
-rw-r--r--test/parse/module/bad-global-invalid-expr.txt4
-rw-r--r--test/roundtrip/generate-func-type-names.txt5
-rw-r--r--test/spec/globals.txt4
-rw-r--r--test/typecheck/bad-callindirect-func-type-mismatch.txt3
-rw-r--r--test/typecheck/bad-global-getglobal-type-mismatch.txt4
-rw-r--r--test/typecheck/bad-global-type-mismatch.txt4
-rw-r--r--test/utils.py5
22 files changed, 79 insertions, 79 deletions
diff --git a/src/wasm-ast-checker.c b/src/wasm-ast-checker.c
index 658c2010..999f556d 100644
--- a/src/wasm-ast-checker.c
+++ b/src/wasm-ast-checker.c
@@ -891,6 +891,8 @@ static void check_func(Context* ctx,
if (wasm_get_result_type(ctx->current_module, func) == WASM_TYPE_MULTIPLE) {
print_error(ctx, CHECK_STYLE_FULL, loc,
"multiple result values not currently supported.");
+ /* don't run any other checks, the won't test the result_type properly */
+ return;
}
if (wasm_decl_has_func_type(&func->decl)) {
const WasmFuncType* func_type;
@@ -916,6 +918,15 @@ static void check_func(Context* ctx,
ctx->current_func = NULL;
}
+static void print_const_expr_error(Context* ctx,
+ const WasmLocation* loc,
+ const char* desc) {
+ print_error(ctx, CHECK_STYLE_FULL, loc,
+ "invalid %s, must be a constant expression; either *.const or "
+ "get_global.",
+ desc);
+}
+
static WasmResult eval_const_expr_i32(Context* ctx,
const WasmExpr* expr,
const char* desc,
@@ -955,11 +966,7 @@ static WasmResult eval_const_expr_i32(Context* ctx,
invalid_expr:
default:
- print_error(
- ctx, CHECK_STYLE_FULL, &expr->loc,
- "invalid %s, must be a constant expression; either *.const or "
- "get_global.",
- desc);
+ print_const_expr_error(ctx, &expr->loc, desc);
return WASM_ERROR;
}
}
@@ -968,47 +975,44 @@ static void check_global(Context* ctx,
const WasmLocation* loc,
const WasmGlobal* global,
int global_index) {
+ static const char s_desc[] = "global initializer expression";
WasmCheckType type = WASM_CHECK_TYPE_VOID;
- WasmBool invalid_expr = WASM_TRUE;
WasmExpr* expr = global->init_expr;
- if (expr->next == NULL) {
- switch (expr->type) {
- case WASM_EXPR_TYPE_CONST:
- type = expr->const_.type;
- invalid_expr = WASM_FALSE;
- break;
+ if (expr->next != NULL) {
+ print_const_expr_error(ctx, loc, s_desc);
+ return;
+ }
- case WASM_EXPR_TYPE_GET_GLOBAL: {
- const WasmGlobal* ref_global = NULL;
- int ref_global_index;
- if (WASM_SUCCEEDED(check_global_var(ctx, &expr->get_global.var,
- &ref_global, &ref_global_index))) {
- type = ref_global->type;
- /* globals can only reference previously defined globals */
- if (ref_global_index >= global_index) {
- print_error(ctx, CHECK_STYLE_FULL, loc,
- "global can only be defined in terms of a previously "
- "defined global.");
- }
- }
- invalid_expr = WASM_FALSE;
- break;
+ switch (expr->type) {
+ case WASM_EXPR_TYPE_CONST:
+ type = expr->const_.type;
+ break;
+
+ case WASM_EXPR_TYPE_GET_GLOBAL: {
+ const WasmGlobal* ref_global = NULL;
+ int ref_global_index;
+ if (WASM_FAILED(check_global_var(ctx, &expr->get_global.var, &ref_global,
+ &ref_global_index))) {
+ return;
}
- default:
- break;
+ type = ref_global->type;
+ /* globals can only reference previously defined globals */
+ if (ref_global_index >= global_index) {
+ print_error(ctx, CHECK_STYLE_FULL, loc,
+ "global can only be defined in terms of a previously "
+ "defined global.");
+ }
+ break;
}
- }
- if (invalid_expr) {
- print_error(ctx, CHECK_STYLE_FULL, loc,
- "invalid global initializer expression. Must be *.const or "
- "get_global.");
- } else {
- check_type(ctx, &expr->loc, type, global->type,
- "global initializer expression");
+ default:
+ print_const_expr_error(ctx, loc, s_desc);
+ return;
}
+
+ check_type(ctx, &expr->loc, type, global->type, s_desc);
}
static void check_import(Context* ctx,
diff --git a/src/wasm-ast-parser.y b/src/wasm-ast-parser.y
index a97ae6ba..a6fee094 100644
--- a/src/wasm-ast-parser.y
+++ b/src/wasm-ast-parser.y
@@ -598,11 +598,7 @@ expr1 :
// split_var_list_as_br_table_targets(expr, $2);
$$ = join_exprs3(&@1, &$4, &$5, expr);
}
- | RETURN {
- WasmExpr* expr = wasm_new_return_expr(parser->allocator);
- $$ = join_exprs1(&@1, expr);
- }
- | RETURN expr {
+ | RETURN expr_list {
WasmExpr* expr = wasm_new_return_expr(parser->allocator);
$$ = join_exprs2(&@1, &$2, expr);
}
diff --git a/test/binary/bad-function-body-size.txt b/test/binary/bad-function-body-size.txt
index 9ba73acb..bb38cdaa 100644
--- a/test/binary/bad-function-body-size.txt
+++ b/test/binary/bad-function-body-size.txt
@@ -2,18 +2,18 @@
;;; TOOL: run-gen-wasm-interp
magic
version
-section("type") { count[1] function params[0] results[1] i32 }
+section("type") { count[1] function params[0] results[0] }
section("function") { count[1] sig[0] }
section("code") {
count[1]
- 0x01 ;; malformed 1 byte function body size (should be 5)
+ 0x02 ;; malformed 2 byte function body size (should be 4)
locals[0]
i32.const
leb_i32(42)
- return arity[1]
+ drop
}
(;; STDERR ;;;
Error running "wasm-interp":
-error: @0x00000028: end_function_body callback failed
+error: @0x00000029: function body longer than given size
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-callindirect-too-few-named.txt b/test/parse/expr/bad-callindirect-too-few-named.txt
index 9fc566d3..ed86af55 100644
--- a/test/parse/expr/bad-callindirect-too-few-named.txt
+++ b/test/parse/expr/bad-callindirect-too-few-named.txt
@@ -1,10 +1,11 @@
;;; ERROR: 1
(module
+ (table anyfunc (elem 0))
(type $t (func (param i32 i32)))
(func $baz
(call_indirect $t (i32.const 0))))
(;; STDERR ;;;
-parse/expr/bad-callindirect-too-few-named.txt:5:6: type stack size too small at call_indirect. got 0, expected at least 2
+parse/expr/bad-callindirect-too-few-named.txt:6:6: type stack size too small at call_indirect. got 0, expected at least 2
(call_indirect $t (i32.const 0))))
^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-callindirect-too-few.txt b/test/parse/expr/bad-callindirect-too-few.txt
index a7748c88..61264f3c 100644
--- a/test/parse/expr/bad-callindirect-too-few.txt
+++ b/test/parse/expr/bad-callindirect-too-few.txt
@@ -1,10 +1,11 @@
;;; ERROR: 1
(module
+ (table anyfunc (elem 0))
(type $t (func (param i32 i32)))
(func
(call_indirect $t (i32.const 0))))
(;; STDERR ;;;
-parse/expr/bad-callindirect-too-few.txt:5:6: type stack size too small at call_indirect. got 0, expected at least 2
+parse/expr/bad-callindirect-too-few.txt:6:6: type stack size too small at call_indirect. got 0, expected at least 2
(call_indirect $t (i32.const 0))))
^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-callindirect-too-many-named.txt b/test/parse/expr/bad-callindirect-too-many-named.txt
index 7d14354a..3b98c236 100644
--- a/test/parse/expr/bad-callindirect-too-many-named.txt
+++ b/test/parse/expr/bad-callindirect-too-many-named.txt
@@ -1,10 +1,11 @@
;;; ERROR: 1
(module
+ (table anyfunc (elem 0))
(type $t (func (param i32 i32)))
(func $baz
(call_indirect $t (i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3))))
(;; STDERR ;;;
-parse/expr/bad-callindirect-too-many-named.txt:4:3: unable to join type i32 (type of last operation) with type void (function signature result type).
+parse/expr/bad-callindirect-too-many-named.txt:5:3: unable to join type i32 (type of last operation) with type void (function signature result type).
(func $baz
^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-callindirect-too-many.txt b/test/parse/expr/bad-callindirect-too-many.txt
index 06ea8dcb..1a4177fa 100644
--- a/test/parse/expr/bad-callindirect-too-many.txt
+++ b/test/parse/expr/bad-callindirect-too-many.txt
@@ -1,10 +1,11 @@
;;; ERROR: 1
(module
+ (table anyfunc (elem 0))
(type $t (func (param i32 i32)))
(func
(call_indirect $t (i32.const 0) (i32.const 1) (i32.const 2) (i32.const 3))))
(;; STDERR ;;;
-parse/expr/bad-callindirect-too-many.txt:4:3: unable to join type i32 (type of last operation) with type void (function signature result type).
+parse/expr/bad-callindirect-too-many.txt:5:3: unable to join type i32 (type of last operation) with type void (function signature result type).
(func
^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-return-multi.txt b/test/parse/expr/bad-return-multi.txt
index 824e4708..b7312e05 100644
--- a/test/parse/expr/bad-return-multi.txt
+++ b/test/parse/expr/bad-return-multi.txt
@@ -2,7 +2,7 @@
(module (func (result f32 f32)
(return (f32.const 0) (f32.const 3.14))))
(;; STDERR ;;;
-parse/expr/bad-return-multi.txt:2:27: syntax error, unexpected VALUE_TYPE, expecting )
+parse/expr/bad-return-multi.txt:2:9: multiple result values not currently supported.
(module (func (result f32 f32)
- ^^^
+ ^^^^^^^^^^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/bad-return-too-many.txt b/test/parse/expr/bad-return-too-many.txt
index 779a9ab4..2d02a792 100644
--- a/test/parse/expr/bad-return-too-many.txt
+++ b/test/parse/expr/bad-return-too-many.txt
@@ -3,7 +3,7 @@
(func (result i32 i32)
(return (i32.const 0) (i32.const 0) (i32.const 0))))
(;; STDERR ;;;
-parse/expr/bad-return-too-many.txt:3:21: syntax error, unexpected VALUE_TYPE, expecting )
+parse/expr/bad-return-too-many.txt:3:3: multiple result values not currently supported.
(func (result i32 i32)
- ^^^
+ ^^^^^^^^^^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/expr/callindirect-named.txt b/test/parse/expr/callindirect-named.txt
index b2b62ccc..afcd1737 100644
--- a/test/parse/expr/callindirect-named.txt
+++ b/test/parse/expr/callindirect-named.txt
@@ -1,3 +1,4 @@
(module
+ (table anyfunc (elem 0))
(type $t (func (param i32)))
(func $g (call_indirect $t (i32.const 0) (i32.const 0))))
diff --git a/test/parse/expr/callindirect.txt b/test/parse/expr/callindirect.txt
index 04da1800..935dcb05 100644
--- a/test/parse/expr/callindirect.txt
+++ b/test/parse/expr/callindirect.txt
@@ -1,3 +1,4 @@
(module
+ (table anyfunc (elem 0))
(type (func (param i32)))
(func (call_indirect 0 (i32.const 0) (i32.const 0))))
diff --git a/test/parse/func/bad-result-empty.txt b/test/parse/func/bad-result-empty.txt
deleted file mode 100644
index a77a5b73..00000000
--- a/test/parse/func/bad-result-empty.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-;;; ERROR: 1
-(module (func (result)))
-(;; STDERR ;;;
-parse/func/bad-result-empty.txt:2:22: syntax error, unexpected ), expecting VALUE_TYPE
-(module (func (result)))
- ^
-;;; STDERR ;;)
diff --git a/test/parse/func/bad-result-multi.txt b/test/parse/func/bad-result-multi.txt
index a2d8af01..1e69c74a 100644
--- a/test/parse/func/bad-result-multi.txt
+++ b/test/parse/func/bad-result-multi.txt
@@ -1,7 +1,7 @@
;;; ERROR: 1
(module (func (result i32 i64)))
(;; STDERR ;;;
-parse/func/bad-result-multi.txt:2:27: syntax error, unexpected VALUE_TYPE, expecting )
+parse/func/bad-result-multi.txt:2:9: multiple result values not currently supported.
(module (func (result i32 i64)))
- ^^^
+ ^^^^^^^^^^^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/parse/func/bad-result-type.txt b/test/parse/func/bad-result-type.txt
index 69e0742d..4a8f9034 100644
--- a/test/parse/func/bad-result-type.txt
+++ b/test/parse/func/bad-result-type.txt
@@ -4,7 +4,4 @@
parse/func/bad-result-type.txt:2:23: unexpected token "foo"
(module (func (result foo)))
^^^
-parse/func/bad-result-type.txt:2:26: syntax error, unexpected ), expecting VALUE_TYPE
-(module (func (result foo)))
- ^
;;; STDERR ;;)
diff --git a/test/parse/func/result-empty.txt b/test/parse/func/result-empty.txt
new file mode 100644
index 00000000..69e82f7a
--- /dev/null
+++ b/test/parse/func/result-empty.txt
@@ -0,0 +1 @@
+(module (func (result)))
diff --git a/test/parse/module/bad-global-invalid-expr.txt b/test/parse/module/bad-global-invalid-expr.txt
index 877ab519..7a2e5373 100644
--- a/test/parse/module/bad-global-invalid-expr.txt
+++ b/test/parse/module/bad-global-invalid-expr.txt
@@ -2,7 +2,7 @@
(module
(global i32 (i32.add (i32.const 1) (i32.const 2))))
(;; STDERR ;;;
-parse/module/bad-global-invalid-expr.txt:3:25: invalid global initializer expression, must be a constant expression; either *.const or get_global.
+parse/module/bad-global-invalid-expr.txt:3:3: invalid global initializer expression, must be a constant expression; either *.const or get_global.
(global i32 (i32.add (i32.const 1) (i32.const 2))))
- ^^^^^^^^^
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/roundtrip/generate-func-type-names.txt b/test/roundtrip/generate-func-type-names.txt
index cfe46cfb..067c6a01 100644
--- a/test/roundtrip/generate-func-type-names.txt
+++ b/test/roundtrip/generate-func-type-names.txt
@@ -1,6 +1,7 @@
;;; TOOL: run-roundtrip
;;; FLAGS: --stdout --generate-names
(module
+ (table anyfunc (elem 0))
(type (func))
(type (func (result i32)))
(import "foo" "bar" (type 0))
@@ -17,5 +18,7 @@
(func $f1 (type $t1) (result i32)
i32.const 0
call_indirect $t0
- i32.const 1))
+ i32.const 1)
+ (table 1 1 anyfunc)
+ (elem (i32.const 0) $f0))
;;; STDOUT ;;)
diff --git a/test/spec/globals.txt b/test/spec/globals.txt
index e780c7c7..cccc946e 100644
--- a/test/spec/globals.txt
+++ b/test/spec/globals.txt
@@ -2,11 +2,11 @@
;;; STDIN_FILE: third_party/testsuite/globals.wast
(;; STDOUT ;;;
assert_invalid error:
- third_party/testsuite/globals.wast:36:11: invalid global initializer expression. Must be *.const or get_global.
+ third_party/testsuite/globals.wast:36:11: invalid global initializer expression, must be a constant expression; either *.const or get_global.
(module (global f32 (f32.neg (f32.const 0))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
assert_invalid error:
- third_party/testsuite/globals.wast:41:11: invalid global initializer expression. Must be *.const or get_global.
+ third_party/testsuite/globals.wast:41:11: invalid global initializer expression, must be a constant expression; either *.const or get_global.
(module (global f32 (get_local 0)))
^^^^^^^^^^^^^^^^^^^^^^^^^^
assert_invalid error:
diff --git a/test/typecheck/bad-callindirect-func-type-mismatch.txt b/test/typecheck/bad-callindirect-func-type-mismatch.txt
index 33fb3a87..9f6cbd58 100644
--- a/test/typecheck/bad-callindirect-func-type-mismatch.txt
+++ b/test/typecheck/bad-callindirect-func-type-mismatch.txt
@@ -1,9 +1,10 @@
;;; ERROR: 1
(module
+ (table anyfunc (elem 0))
(type $t (func))
(func (call_indirect $t (f32.const 0))))
(;; STDERR ;;;
-typecheck/bad-callindirect-func-type-mismatch.txt:4:10: type mismatch at call_indirect function index. got f32, expected i32
+typecheck/bad-callindirect-func-type-mismatch.txt:5:10: type mismatch at call_indirect function index. got f32, expected i32
(func (call_indirect $t (f32.const 0))))
^^^^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/typecheck/bad-global-getglobal-type-mismatch.txt b/test/typecheck/bad-global-getglobal-type-mismatch.txt
index 49fa5011..5dccddef 100644
--- a/test/typecheck/bad-global-getglobal-type-mismatch.txt
+++ b/test/typecheck/bad-global-getglobal-type-mismatch.txt
@@ -3,7 +3,7 @@
(global i32 (i32.const 1))
(global f32 (get_global 0)))
(;; STDERR ;;;
-typecheck/bad-global-getglobal-type-mismatch.txt:4:3: type mismatch at global initializer expression. got i32, expected f32
+typecheck/bad-global-getglobal-type-mismatch.txt:4:16: type mismatch at global initializer expression. got i32, expected f32
(global f32 (get_global 0)))
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ ^^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/typecheck/bad-global-type-mismatch.txt b/test/typecheck/bad-global-type-mismatch.txt
index 2599583b..11534bb2 100644
--- a/test/typecheck/bad-global-type-mismatch.txt
+++ b/test/typecheck/bad-global-type-mismatch.txt
@@ -2,7 +2,7 @@
(module
(global i32 (f32.const 1)))
(;; STDERR ;;;
-typecheck/bad-global-type-mismatch.txt:3:3: type mismatch at global initializer expression. got f32, expected i32
+typecheck/bad-global-type-mismatch.txt:3:16: type mismatch at global initializer expression. got f32, expected i32
(global i32 (f32.const 1)))
- ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ ^^^^^^^^^
;;; STDERR ;;)
diff --git a/test/utils.py b/test/utils.py
index 836100b7..4e734b83 100644
--- a/test/utils.py
+++ b/test/utils.py
@@ -140,7 +140,7 @@ def Hexdump(data):
while p < line_end:
for i in xrange(DUMP_OCTETS_PER_GROUP):
if p < end:
- line += '%02x' % ord(data[p])
+ line += '%02x' % data[p]
else:
line += ' '
p += 1
@@ -151,8 +151,7 @@ def Hexdump(data):
if p >= end:
break
x = data[p]
- o = ord(x)
- if o >= 32 and o < 0x7f:
+ if x >= 32 and x < 0x7f:
line += '%c' % x
else:
line += '.'