Implement GC (Garbage Collection) feature for interpreter, AOT and LLVM-JIT (#3125)

Implement the GC (Garbage Collection) feature for interpreter mode,
AOT mode and LLVM-JIT mode, and support most features of the latest
spec proposal, and also enable the stringref feature.

Use `cmake -DWAMR_BUILD_GC=1/0` to enable/disable the feature,
and `wamrc --enable-gc` to generate the AOT file with GC supported.

And update the AOT file version from 2 to 3 since there are many AOT
ABI breaks, including the changes of AOT file format, the changes of
AOT module/memory instance layouts, the AOT runtime APIs for the
AOT code to invoke and so on.
This commit is contained in:
Wenyong Huang
2024-02-06 20:47:11 +08:00
committed by GitHub
parent 5931aaacbe
commit 16a4d71b34
98 changed files with 33469 additions and 3159 deletions

View File

@ -94,7 +94,7 @@ def ignore_the_case(
return True
if gc_flag:
if case_name in ["type-canon", "type-equivalence", "type-rec"]:
if case_name in ["type-equivalence", "type-rec", "array_init_elem", "array_init_data"]:
return True
if sgx_flag:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
diff --git a/test/core/return_call.wast b/test/core/return_call.wast
index ad66acca..b27af19b 100644
--- a/test/core/return_call.wast
+++ b/test/core/return_call.wast
@@ -102,20 +102,20 @@
(assert_return (invoke "count" (i64.const 0)) (i64.const 0))
(assert_return (invoke "count" (i64.const 1000)) (i64.const 0))
-(assert_return (invoke "count" (i64.const 100_000)) (i64.const 0))
+(assert_return (invoke "count" (i64.const 1001)) (i64.const 0))
(assert_return (invoke "even" (i64.const 0)) (i32.const 44))
(assert_return (invoke "even" (i64.const 1)) (i32.const 99))
(assert_return (invoke "even" (i64.const 100)) (i32.const 44))
(assert_return (invoke "even" (i64.const 77)) (i32.const 99))
-(assert_return (invoke "even" (i64.const 100_000)) (i32.const 44))
-(assert_return (invoke "even" (i64.const 100_001)) (i32.const 99))
+(assert_return (invoke "even" (i64.const 1000)) (i32.const 44))
+(assert_return (invoke "even" (i64.const 1001)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 0)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 1)) (i32.const 44))
(assert_return (invoke "odd" (i64.const 200)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 77)) (i32.const 44))
-(assert_return (invoke "odd" (i64.const 100_000)) (i32.const 99))
-(assert_return (invoke "odd" (i64.const 99_999)) (i32.const 44))
+(assert_return (invoke "odd" (i64.const 1000)) (i32.const 99))
+(assert_return (invoke "odd" (i64.const 999)) (i32.const 44))
;; Invalid typing
diff --git a/test/core/return_call_indirect.wast b/test/core/return_call_indirect.wast
index 6b95c24b..a9e86d42 100644
--- a/test/core/return_call_indirect.wast
+++ b/test/core/return_call_indirect.wast
@@ -257,14 +257,14 @@
(assert_return (invoke "even" (i32.const 1)) (i32.const 99))
(assert_return (invoke "even" (i32.const 100)) (i32.const 44))
(assert_return (invoke "even" (i32.const 77)) (i32.const 99))
-(assert_return (invoke "even" (i32.const 100_000)) (i32.const 44))
-(assert_return (invoke "even" (i32.const 111_111)) (i32.const 99))
+(assert_return (invoke "even" (i32.const 1000)) (i32.const 44))
+(assert_return (invoke "even" (i32.const 1111)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 0)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 1)) (i32.const 44))
(assert_return (invoke "odd" (i32.const 200)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 77)) (i32.const 44))
-(assert_return (invoke "odd" (i32.const 100_002)) (i32.const 99))
-(assert_return (invoke "odd" (i32.const 100_003)) (i32.const 44))
+(assert_return (invoke "odd" (i32.const 1002)) (i32.const 99))
+(assert_return (invoke "odd" (i32.const 1003)) (i32.const 44))
;; Invalid syntax

View File

@ -626,7 +626,7 @@ def vector_value_comparison(out, expected):
int(expected_val[1]) if not "0x" in expected_val[1] else int(expected_val[1], 16))
if lane_type in ["i8x16", "i16x8", "i32x4", "i64x2"]:
return out_packed == expected_packed;
return out_packed == expected_packed
else:
assert(lane_type in ["f32x4", "f64x2"]), "unexpected lane_type"
@ -817,7 +817,7 @@ def test_assert_return(r, opts, form):
n = re.search('^\(assert_return\s+\(invoke\s+\$((?:[^\s])*)\s+"([^"]*)"*()()\)\s*\)\s*$', form, re.S)
if not m and not n:
if re.search('^\(assert_return\s+\(get.*\).*\)$', form, re.S):
log("ignoring assert_return get");
log("ignoring assert_return get")
return
else:
raise Exception("unparsed assert_return: '%s'" % form)
@ -898,6 +898,7 @@ def test_assert_return(r, opts, form):
except:
_, exc, _ = sys.exc_info()
log("Run wamrc failed:\n got: '%s'" % r.buf)
ret_code = 1
sys.exit(1)
r = run_wasm_with_repl(module+".wasm", module+".aot" if test_aot else module, opts, r)
# Wait for the initial prompt
@ -963,6 +964,7 @@ def test_assert_trap(r, opts, form):
except:
_, exc, _ = sys.exc_info()
log("Run wamrc failed:\n got: '%s'" % r.buf)
ret_code = 1
sys.exit(1)
r = run_wasm_with_repl(module+".wasm", module+".aot" if test_aot else module, opts, r)
# Wait for the initial prompt
@ -1091,7 +1093,7 @@ def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts):
return True
def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = 'default'):
log("Compiling AOT to '%s'" % aot_tempfile)
log("Compiling '%s' to '%s'" % (wasm_tempfile, aot_tempfile))
cmd = [opts.aot_compiler]
if test_target in aot_target_options_map:
@ -1110,6 +1112,10 @@ def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = '
if opts.multi_thread:
cmd.append("--enable-multi-thread")
if opts.gc:
cmd.append("--enable-gc")
cmd.append("--enable-tail-call")
if output == 'object':
cmd.append("--format=object")
elif output == 'ir':
@ -1223,6 +1229,7 @@ def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile,
else:
log("Run wamrc failed:\n expected: '%s'\n got: '%s'" % \
(expected, r.buf))
ret_code = 1
sys.exit(1)
r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r)
@ -1319,26 +1326,47 @@ if __name__ == "__main__":
log("Out exception includes expected one, pass:")
log(" Expected: %s" % error_msg)
log(" Got: %s" % r.buf)
continue
# one case in binary.wast
elif (error_msg == "unexpected end of section or function"
and r.buf.find("unexpected end")):
continue
# one case in binary.wast
elif (error_msg == "invalid value type"
and r.buf.find("unexpected end")):
continue
# one case in binary.wast
elif (error_msg == "integer too large"
and r.buf.find("tables cannot be shared")):
continue
# one case in binary.wast
elif (error_msg == "zero byte expected"
and r.buf.find("unknown table")):
continue
# one case in binary.wast
elif (error_msg == "invalid section id"
and r.buf.find("unexpected end of section or function")):
continue
# one case in binary.wast
elif (error_msg == "illegal opcode"
and r.buf.find("unexpected end of section or function")):
continue
# one case in custom.wast
elif (error_msg == "length out of bounds"
and r.buf.find("unexpected end")):
continue
# several cases in binary-leb128.wast
elif (error_msg == "integer representation too long"
and r.buf.find("invalid section id")):
continue
else:
log("Run wamrc failed:\n expected: '%s'\n got: '%s'" % \
(error_msg, r.buf))
continue
ret_code = 1
sys.exit(1)
r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r)
if (error_msg == "unexpected end of section or function"):
# one case in binary.wast
assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True)
elif (error_msg == "invalid value type"):
# one case in binary.wast
assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True)
elif (error_msg == "length out of bounds"):
# one case in custom.wast
assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True)
elif (error_msg == "integer representation too long"):
# several cases in binary-leb128.wast
assert_prompt(r, ["invalid section id", error_msg], opts.start_timeout, True)
elif re.match("^\(assert_malformed\s*\(module quote", form):
log("ignoring assert_malformed module quote")
else:
@ -1371,6 +1399,7 @@ if __name__ == "__main__":
except:
_, exc, _ = sys.exc_info()
log("Run wamrc failed:\n got: '%s'" % r.buf)
ret_code = 1
sys.exit(1)
temp_module_table[module_name] = temp_files[1]
r = run_wasm_with_repl(temp_files[1], temp_files[2] if test_aot else None, opts, r)
@ -1385,6 +1414,7 @@ if __name__ == "__main__":
except:
_, exc, _ = sys.exc_info()
log("Run wamrc failed:\n got: '%s'" % r.buf)
ret_code = 1
sys.exit(1)
r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r)
@ -1468,4 +1498,3 @@ if __name__ == "__main__":
log("Leaving tempfiles: %s" % ([wast_tempfile, wasm_tempfile]))
sys.exit(ret_code)

View File

@ -1,202 +0,0 @@
;; Test `return_call` operator
(module
;; Auxiliary definitions
(func $const-i32 (result i32) (i32.const 0x132))
(func $const-i64 (result i64) (i64.const 0x164))
(func $const-f32 (result f32) (f32.const 0xf32))
(func $const-f64 (result f64) (f64.const 0xf64))
(func $id-i32 (param i32) (result i32) (get_local 0))
(func $id-i64 (param i64) (result i64) (get_local 0))
(func $id-f32 (param f32) (result f32) (get_local 0))
(func $id-f64 (param f64) (result f64) (get_local 0))
(func $f32-i32 (param f32 i32) (result i32) (get_local 1))
(func $i32-i64 (param i32 i64) (result i64) (get_local 1))
(func $f64-f32 (param f64 f32) (result f32) (get_local 1))
(func $i64-f64 (param i64 f64) (result f64) (get_local 1))
;; Typing
(func (export "type-i32") (result i32) (return_call $const-i32))
(func (export "type-i64") (result i64) (return_call $const-i64))
(func (export "type-f32") (result f32) (return_call $const-f32))
(func (export "type-f64") (result f64) (return_call $const-f64))
(func (export "type-first-i32") (result i32) (return_call $id-i32 (i32.const 32)))
(func (export "type-first-i64") (result i64) (return_call $id-i64 (i64.const 64)))
(func (export "type-first-f32") (result f32) (return_call $id-f32 (f32.const 1.32)))
(func (export "type-first-f64") (result f64) (return_call $id-f64 (f64.const 1.64)))
(func (export "type-second-i32") (result i32)
(return_call $f32-i32 (f32.const 32.1) (i32.const 32))
)
(func (export "type-second-i64") (result i64)
(return_call $i32-i64 (i32.const 32) (i64.const 64))
)
(func (export "type-second-f32") (result f32)
(return_call $f64-f32 (f64.const 64) (f32.const 32))
)
(func (export "type-second-f64") (result f64)
(return_call $i64-f64 (i64.const 64) (f64.const 64.1))
)
;; Recursion
(func $fac-acc (export "fac-acc") (param i64 i64) (result i64)
(if (result i64) (i64.eqz (get_local 0))
(then (get_local 1))
(else
(return_call $fac-acc
(i64.sub (get_local 0) (i64.const 1))
(i64.mul (get_local 0) (get_local 1))
)
)
)
)
(func $count (export "count") (param i64) (result i64)
(if (result i64) (i64.eqz (get_local 0))
(then (get_local 0))
(else (return_call $count (i64.sub (get_local 0) (i64.const 1))))
)
)
(func $even (export "even") (param i64) (result i32)
(if (result i32) (i64.eqz (get_local 0))
(then (i32.const 44))
(else (return_call $odd (i64.sub (get_local 0) (i64.const 1))))
)
)
(func $odd (export "odd") (param i64) (result i32)
(if (result i32) (i64.eqz (get_local 0))
(then (i32.const 99))
(else (return_call $even (i64.sub (get_local 0) (i64.const 1))))
)
)
)
(assert_return (invoke "type-i32") (i32.const 0x132))
(assert_return (invoke "type-i64") (i64.const 0x164))
(assert_return (invoke "type-f32") (f32.const 0xf32))
(assert_return (invoke "type-f64") (f64.const 0xf64))
(assert_return (invoke "type-first-i32") (i32.const 32))
(assert_return (invoke "type-first-i64") (i64.const 64))
(assert_return (invoke "type-first-f32") (f32.const 1.32))
(assert_return (invoke "type-first-f64") (f64.const 1.64))
(assert_return (invoke "type-second-i32") (i32.const 32))
(assert_return (invoke "type-second-i64") (i64.const 64))
(assert_return (invoke "type-second-f32") (f32.const 32))
(assert_return (invoke "type-second-f64") (f64.const 64.1))
(assert_return (invoke "fac-acc" (i64.const 0) (i64.const 1)) (i64.const 1))
(assert_return (invoke "fac-acc" (i64.const 1) (i64.const 1)) (i64.const 1))
(assert_return (invoke "fac-acc" (i64.const 5) (i64.const 1)) (i64.const 120))
(assert_return
(invoke "fac-acc" (i64.const 25) (i64.const 1))
(i64.const 7034535277573963776)
)
(assert_return (invoke "count" (i64.const 0)) (i64.const 0))
(assert_return (invoke "count" (i64.const 1000)) (i64.const 0))
(assert_return (invoke "count" (i64.const 1_000_000)) (i64.const 0))
(assert_return (invoke "even" (i64.const 0)) (i32.const 44))
(assert_return (invoke "even" (i64.const 1)) (i32.const 99))
(assert_return (invoke "even" (i64.const 100)) (i32.const 44))
(assert_return (invoke "even" (i64.const 77)) (i32.const 99))
(assert_return (invoke "even" (i64.const 1_000_000)) (i32.const 44))
(assert_return (invoke "even" (i64.const 1_000_001)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 0)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 1)) (i32.const 44))
(assert_return (invoke "odd" (i64.const 200)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 77)) (i32.const 44))
(assert_return (invoke "odd" (i64.const 1_000_000)) (i32.const 99))
(assert_return (invoke "odd" (i64.const 999_999)) (i32.const 44))
;; Invalid typing
(assert_invalid
(module
(func $type-void-vs-num (result i32) (return_call 1) (i32.const 0))
(func)
)
"type mismatch"
)
(assert_invalid
(module
(func $type-num-vs-num (result i32) (return_call 1) (i32.const 0))
(func (result i64) (i64.const 1))
)
"type mismatch"
)
(assert_invalid
(module
(func $arity-0-vs-1 (return_call 1))
(func (param i32))
)
"type mismatch"
)
(assert_invalid
(module
(func $arity-0-vs-2 (return_call 1))
(func (param f64 i32))
)
"type mismatch"
)
(module
(func $arity-1-vs-0 (i32.const 1) (return_call 1))
(func)
)
(module
(func $arity-2-vs-0 (f64.const 2) (i32.const 1) (return_call 1))
(func)
)
(assert_invalid
(module
(func $type-first-void-vs-num (return_call 1 (nop) (i32.const 1)))
(func (param i32 i32))
)
"type mismatch"
)
(assert_invalid
(module
(func $type-second-void-vs-num (return_call 1 (i32.const 1) (nop)))
(func (param i32 i32))
)
"type mismatch"
)
(assert_invalid
(module
(func $type-first-num-vs-num (return_call 1 (f64.const 1) (i32.const 1)))
(func (param i32 f64))
)
"type mismatch"
)
(assert_invalid
(module
(func $type-second-num-vs-num (return_call 1 (i32.const 1) (f64.const 1)))
(func (param f64 i32))
)
"type mismatch"
)
;; Unbound function
(assert_invalid
(module (func $unbound-func (return_call 1)))
"unknown function"
)
(assert_invalid
(module (func $large-func (return_call 1012321300)))
"unknown function"
)

View File

@ -1,511 +0,0 @@
;; Test `return_call_indirect` operator
(module
;; Auxiliary definitions
(type $proc (func))
(type $out-i32 (func (result i32)))
(type $out-i64 (func (result i64)))
(type $out-f32 (func (result f32)))
(type $out-f64 (func (result f64)))
(type $over-i32 (func (param i32) (result i32)))
(type $over-i64 (func (param i64) (result i64)))
(type $over-f32 (func (param f32) (result f32)))
(type $over-f64 (func (param f64) (result f64)))
(type $f32-i32 (func (param f32 i32) (result i32)))
(type $i32-i64 (func (param i32 i64) (result i64)))
(type $f64-f32 (func (param f64 f32) (result f32)))
(type $i64-f64 (func (param i64 f64) (result f64)))
(type $over-i32-duplicate (func (param i32) (result i32)))
(type $over-i64-duplicate (func (param i64) (result i64)))
(type $over-f32-duplicate (func (param f32) (result f32)))
(type $over-f64-duplicate (func (param f64) (result f64)))
(func $const-i32 (type $out-i32) (i32.const 0x132))
(func $const-i64 (type $out-i64) (i64.const 0x164))
(func $const-f32 (type $out-f32) (f32.const 0xf32))
(func $const-f64 (type $out-f64) (f64.const 0xf64))
(func $id-i32 (type $over-i32) (get_local 0))
(func $id-i64 (type $over-i64) (get_local 0))
(func $id-f32 (type $over-f32) (get_local 0))
(func $id-f64 (type $over-f64) (get_local 0))
(func $i32-i64 (type $i32-i64) (get_local 1))
(func $i64-f64 (type $i64-f64) (get_local 1))
(func $f32-i32 (type $f32-i32) (get_local 1))
(func $f64-f32 (type $f64-f32) (get_local 1))
(func $over-i32-duplicate (type $over-i32-duplicate) (get_local 0))
(func $over-i64-duplicate (type $over-i64-duplicate) (get_local 0))
(func $over-f32-duplicate (type $over-f32-duplicate) (get_local 0))
(func $over-f64-duplicate (type $over-f64-duplicate) (get_local 0))
(table anyfunc
(elem
$const-i32 $const-i64 $const-f32 $const-f64
$id-i32 $id-i64 $id-f32 $id-f64
$f32-i32 $i32-i64 $f64-f32 $i64-f64
$fac $fac-acc $even $odd
$over-i32-duplicate $over-i64-duplicate
$over-f32-duplicate $over-f64-duplicate
)
)
;; Syntax
(func
(return_call_indirect (i32.const 0))
(return_call_indirect (param i64) (i64.const 0) (i32.const 0))
(return_call_indirect (param i64) (param) (param f64 i32 i64)
(i64.const 0) (f64.const 0) (i32.const 0) (i64.const 0) (i32.const 0)
)
(return_call_indirect (result) (i32.const 0))
)
(func (result i32)
(return_call_indirect (result i32) (i32.const 0))
(return_call_indirect (result i32) (result) (i32.const 0))
(return_call_indirect (param i64) (result i32) (i64.const 0) (i32.const 0))
(return_call_indirect
(param) (param i64) (param) (param f64 i32 i64) (param) (param)
(result) (result i32) (result) (result)
(i64.const 0) (f64.const 0) (i32.const 0) (i64.const 0) (i32.const 0)
)
)
(func (result i64)
(return_call_indirect (type $over-i64) (param i64) (result i64)
(i64.const 0) (i32.const 0)
)
)
;; Typing
(func (export "type-i32") (result i32)
(return_call_indirect (type $out-i32) (i32.const 0))
)
(func (export "type-i64") (result i64)
(return_call_indirect (type $out-i64) (i32.const 1))
)
(func (export "type-f32") (result f32)
(return_call_indirect (type $out-f32) (i32.const 2))
)
(func (export "type-f64") (result f64)
(return_call_indirect (type $out-f64) (i32.const 3))
)
(func (export "type-index") (result i64)
(return_call_indirect (type $over-i64) (i64.const 100) (i32.const 5))
)
(func (export "type-first-i32") (result i32)
(return_call_indirect (type $over-i32) (i32.const 32) (i32.const 4))
)
(func (export "type-first-i64") (result i64)
(return_call_indirect (type $over-i64) (i64.const 64) (i32.const 5))
)
(func (export "type-first-f32") (result f32)
(return_call_indirect (type $over-f32) (f32.const 1.32) (i32.const 6))
)
(func (export "type-first-f64") (result f64)
(return_call_indirect (type $over-f64) (f64.const 1.64) (i32.const 7))
)
(func (export "type-second-i32") (result i32)
(return_call_indirect (type $f32-i32)
(f32.const 32.1) (i32.const 32) (i32.const 8)
)
)
(func (export "type-second-i64") (result i64)
(return_call_indirect (type $i32-i64)
(i32.const 32) (i64.const 64) (i32.const 9)
)
)
(func (export "type-second-f32") (result f32)
(return_call_indirect (type $f64-f32)
(f64.const 64) (f32.const 32) (i32.const 10)
)
)
(func (export "type-second-f64") (result f64)
(return_call_indirect (type $i64-f64)
(i64.const 64) (f64.const 64.1) (i32.const 11)
)
)
;; Dispatch
(func (export "dispatch") (param i32 i64) (result i64)
(return_call_indirect (type $over-i64) (get_local 1) (get_local 0))
)
(func (export "dispatch-structural") (param i32) (result i64)
(return_call_indirect (type $over-i64-duplicate)
(i64.const 9) (get_local 0)
)
)
;; Recursion
(func $fac (export "fac") (type $over-i64)
(return_call_indirect (param i64 i64) (result i64)
(get_local 0) (i64.const 1) (i32.const 13)
)
)
(func $fac-acc (param i64 i64) (result i64)
(if (result i64) (i64.eqz (get_local 0))
(then (get_local 1))
(else
(return_call_indirect (param i64 i64) (result i64)
(i64.sub (get_local 0) (i64.const 1))
(i64.mul (get_local 0) (get_local 1))
(i32.const 13)
)
)
)
)
(func $even (export "even") (param i32) (result i32)
(if (result i32) (i32.eqz (get_local 0))
(then (i32.const 44))
(else
(return_call_indirect (type $over-i32)
(i32.sub (get_local 0) (i32.const 1))
(i32.const 15)
)
)
)
)
(func $odd (export "odd") (param i32) (result i32)
(if (result i32) (i32.eqz (get_local 0))
(then (i32.const 99))
(else
(return_call_indirect (type $over-i32)
(i32.sub (get_local 0) (i32.const 1))
(i32.const 14)
)
)
)
)
)
(assert_return (invoke "type-i32") (i32.const 0x132))
(assert_return (invoke "type-i64") (i64.const 0x164))
(assert_return (invoke "type-f32") (f32.const 0xf32))
(assert_return (invoke "type-f64") (f64.const 0xf64))
(assert_return (invoke "type-index") (i64.const 100))
(assert_return (invoke "type-first-i32") (i32.const 32))
(assert_return (invoke "type-first-i64") (i64.const 64))
(assert_return (invoke "type-first-f32") (f32.const 1.32))
(assert_return (invoke "type-first-f64") (f64.const 1.64))
(assert_return (invoke "type-second-i32") (i32.const 32))
(assert_return (invoke "type-second-i64") (i64.const 64))
(assert_return (invoke "type-second-f32") (f32.const 32))
(assert_return (invoke "type-second-f64") (f64.const 64.1))
(assert_return (invoke "dispatch" (i32.const 5) (i64.const 2)) (i64.const 2))
(assert_return (invoke "dispatch" (i32.const 5) (i64.const 5)) (i64.const 5))
(assert_return (invoke "dispatch" (i32.const 12) (i64.const 5)) (i64.const 120))
(assert_return (invoke "dispatch" (i32.const 17) (i64.const 2)) (i64.const 2))
(assert_trap (invoke "dispatch" (i32.const 0) (i64.const 2)) "indirect call type mismatch")
(assert_trap (invoke "dispatch" (i32.const 15) (i64.const 2)) "indirect call type mismatch")
(assert_trap (invoke "dispatch" (i32.const 20) (i64.const 2)) "undefined element")
(assert_trap (invoke "dispatch" (i32.const -1) (i64.const 2)) "undefined element")
(assert_trap (invoke "dispatch" (i32.const 1213432423) (i64.const 2)) "undefined element")
(assert_return (invoke "dispatch-structural" (i32.const 5)) (i64.const 9))
(assert_return (invoke "dispatch-structural" (i32.const 5)) (i64.const 9))
(assert_return (invoke "dispatch-structural" (i32.const 12)) (i64.const 362880))
(assert_return (invoke "dispatch-structural" (i32.const 17)) (i64.const 9))
(assert_trap (invoke "dispatch-structural" (i32.const 11)) "indirect call type mismatch")
(assert_trap (invoke "dispatch-structural" (i32.const 16)) "indirect call type mismatch")
(assert_return (invoke "fac" (i64.const 0)) (i64.const 1))
(assert_return (invoke "fac" (i64.const 1)) (i64.const 1))
(assert_return (invoke "fac" (i64.const 5)) (i64.const 120))
(assert_return (invoke "fac" (i64.const 25)) (i64.const 7034535277573963776))
(assert_return (invoke "even" (i32.const 0)) (i32.const 44))
(assert_return (invoke "even" (i32.const 1)) (i32.const 99))
(assert_return (invoke "even" (i32.const 100)) (i32.const 44))
(assert_return (invoke "even" (i32.const 77)) (i32.const 99))
(assert_return (invoke "even" (i32.const 100_000)) (i32.const 44))
(assert_return (invoke "even" (i32.const 111_111)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 0)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 1)) (i32.const 44))
(assert_return (invoke "odd" (i32.const 200)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 77)) (i32.const 44))
(assert_return (invoke "odd" (i32.const 200_002)) (i32.const 99))
(assert_return (invoke "odd" (i32.const 300_003)) (i32.const 44))
;; Invalid syntax
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (type $sig) (result i32) (param i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (param i32) (type $sig) (result i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (param i32) (result i32) (type $sig)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (result i32) (type $sig) (param i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (result i32) (param i32) (type $sig)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (result i32) (param i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"unexpected token"
)
(assert_malformed
(module quote
"(table 0 anyfunc)"
"(func (return_call_indirect (param $x i32) (i32.const 0) (i32.const 0)))"
)
"unexpected token"
)
(assert_malformed
(module quote
"(type $sig (func))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (type $sig) (result i32) (i32.const 0))"
")"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (type $sig) (result i32) (i32.const 0))"
")"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32) (result i32)))"
"(table 0 anyfunc)"
"(func"
" (return_call_indirect (type $sig) (param i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"inline function type"
)
(assert_malformed
(module quote
"(type $sig (func (param i32 i32) (result i32)))"
"(table 0 anyfunc)"
"(func (result i32)"
" (return_call_indirect (type $sig) (param i32) (result i32)"
" (i32.const 0) (i32.const 0)"
" )"
")"
)
"inline function type"
)
;; Invalid typing
(assert_invalid
(module
(type (func))
(func $no-table (return_call_indirect (type 0) (i32.const 0)))
)
"unknown table"
)
(assert_invalid
(module
(type (func))
(table 0 anyfunc)
(func $type-void-vs-num (i32.eqz (return_call_indirect (type 0) (i32.const 0))))
)
"type mismatch"
)
(assert_invalid
(module
(type (func (result i64)))
(table 0 anyfunc)
(func $type-num-vs-num (i32.eqz (return_call_indirect (type 0) (i32.const 0))))
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param i32)))
(table 0 anyfunc)
(func $arity-0-vs-1 (return_call_indirect (type 0) (i32.const 0)))
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param f64 i32)))
(table 0 anyfunc)
(func $arity-0-vs-2 (return_call_indirect (type 0) (i32.const 0)))
)
"type mismatch"
)
(module
(type (func))
(table 0 anyfunc)
(func $arity-1-vs-0 (return_call_indirect (type 0) (i32.const 1) (i32.const 0)))
)
(module
(type (func))
(table 0 anyfunc)
(func $arity-2-vs-0
(return_call_indirect (type 0) (f64.const 2) (i32.const 1) (i32.const 0))
)
)
(assert_invalid
(module
(type (func (param i32)))
(table 0 anyfunc)
(func $type-func-void-vs-i32 (return_call_indirect (type 0) (i32.const 1) (nop)))
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param i32)))
(table 0 anyfunc)
(func $type-func-num-vs-i32 (return_call_indirect (type 0) (i32.const 0) (i64.const 1)))
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param i32 i32)))
(table 0 anyfunc)
(func $type-first-void-vs-num
(return_call_indirect (type 0) (nop) (i32.const 1) (i32.const 0))
)
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param i32 i32)))
(table 0 anyfunc)
(func $type-second-void-vs-num
(return_call_indirect (type 0) (i32.const 1) (nop) (i32.const 0))
)
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param i32 f64)))
(table 0 anyfunc)
(func $type-first-num-vs-num
(return_call_indirect (type 0) (f64.const 1) (i32.const 1) (i32.const 0))
)
)
"type mismatch"
)
(assert_invalid
(module
(type (func (param f64 i32)))
(table 0 anyfunc)
(func $type-second-num-vs-num
(return_call_indirect (type 0) (i32.const 1) (f64.const 1) (i32.const 0))
)
)
"type mismatch"
)
;; Unbound type
(assert_invalid
(module
(table 0 anyfunc)
(func $unbound-type (return_call_indirect (type 1) (i32.const 0)))
)
"unknown type"
)
(assert_invalid
(module
(table 0 anyfunc)
(func $large-type (return_call_indirect (type 1012321300) (i32.const 0)))
)
"unknown type"
)
;; Unbound function in table
(assert_invalid
(module (table anyfunc (elem 0 0)))
"unknown function"
)

View File

@ -211,6 +211,21 @@ index 1ea2b06..8eded37 100644
(assert_return (invoke $module1 "call-8") (i32.const 69))
(assert_return (invoke $module1 "call-9") (i32.const 70))
+;)
diff --git a/test/core/table.wast b/test/core/table.wast
index 0bc43ca6..ee5209ec 100644
--- a/test/core/table.wast
+++ b/test/core/table.wast
@@ -8,8 +8,8 @@
(module (table 0 65536 funcref))
(module (table 0 0xffff_ffff funcref))
-(assert_invalid (module (table 0 funcref) (table 0 funcref)) "multiple tables")
-(assert_invalid (module (table (import "spectest" "table") 0 funcref) (table 0 funcref)) "multiple tables")
+(module (table 0 funcref) (table 0 funcref))
+(module (table (import "spectest" "table") 0 funcref) (table 0 funcref))
(assert_invalid (module (elem (i32.const 0))) "unknown table")
(assert_invalid (module (elem (i32.const 0) $f) (func $f)) "unknown table")
diff --git a/test/core/thread.wast b/test/core/thread.wast
index c3456a6..83fc281 100644
--- a/test/core/thread.wast
@ -228,3 +243,23 @@ index c3456a6..83fc281 100644
(wait $T1)
(wait $T2)
+;)
diff --git a/test/core/unreached-invalid.wast b/test/core/unreached-invalid.wast
index 6ef4ac55..9a2387a3 100644
--- a/test/core/unreached-invalid.wast
+++ b/test/core/unreached-invalid.wast
@@ -535,6 +535,7 @@
))
"type mismatch"
)
+(; invalid case, the module is fine for the latest spec interpreter
(assert_invalid
(module (func $type-br_table-label-num-vs-label-num-after-unreachable
(block (result f64)
@@ -549,6 +550,7 @@
))
"type mismatch"
)
+;)
(assert_invalid
(module (func $type-block-value-nested-unreachable-num-vs-void

View File

@ -462,13 +462,19 @@ function spec_test()
pushd spec
git restore . && git clean -ffd .
# Sync constant expression descriptions
git reset --hard 62beb94ddd41987517781732f17f213d8b866dcc
# Reset to commit: "[test] Unify the error message."
git reset --hard 0caaadc65b5e1910512d8ae228502edcf9d60390
git apply ../../spec-test-script/gc_ignore_cases.patch
if [[ ${ENABLE_QEMU} == 1 ]]; then
# Decrease the recursive count for tail call cases as nuttx qemu's
# native stack size is much smaller
git apply ../../spec-test-script/gc_nuttx_tail_call.patch
fi
echo "compile the reference intepreter"
pushd interpreter
make opt
make
popd
fi
@ -819,6 +825,7 @@ function trigger()
local EXTRA_COMPILE_FLAGS=""
# default enabled features
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
if [[ ${ENABLE_MULTI_MODULE} == 1 ]];then
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=1"
@ -828,9 +835,6 @@ function trigger()
if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=0"
else
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
fi
if [[ ${ENABLE_SIMD} == 1 ]]; then
@ -841,8 +845,8 @@ function trigger()
if [[ ${ENABLE_GC} == 1 ]]; then
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC=1"
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
fi
if [[ ${ENABLE_DEBUG_VERSION} == 1 ]]; then