cranelift: move wasmtests in cranelift-wasm

Move test data used by cranelift-wasm's tests in
the crate directory, to make the tests autonomous.

Fixes #2910
This commit is contained in:
Olivier Lemasle
2021-05-18 22:48:52 +02:00
parent 18c61cdfa4
commit 954f7d3876
54 changed files with 2 additions and 2 deletions

View File

@@ -10,7 +10,7 @@ use target_lexicon::triple;
#[test]
fn testsuite() {
let mut paths: Vec<_> = fs::read_dir("../wasmtests")
let mut paths: Vec<_> = fs::read_dir("./wasmtests")
.unwrap()
.map(|r| r.unwrap())
.filter(|p| {
@@ -36,7 +36,7 @@ fn testsuite() {
#[test]
fn use_fallthrough_return() {
let flags = Flags::new(settings::builder());
let path = Path::new("../wasmtests/use_fallthrough_return.wat");
let path = Path::new("./wasmtests/use_fallthrough_return.wat");
let data = read_module(&path);
handle_module(data, &flags, ReturnMode::FallthroughReturn);
}

View File

@@ -0,0 +1,13 @@
(module
(memory 1)
(func $main (local i32)
(set_local 0 (i32.sub (i32.const 4) (i32.const 4)))
(if
(get_local 0)
(then unreachable)
(else (drop (i32.mul (i32.const 6) (get_local 0))))
)
)
(start $main)
(data (i32.const 0) "abcdefgh")
)

View File

@@ -0,0 +1,30 @@
(module
(func (result i32)
(block (result i32)
(block (result i32)
(block (result i32)
(br_table 0 1 2 3 (i32.const 42) (i32.const 0))
)
)
)
)
(func (result i32)
(block (result i32)
(block (result i32)
(block (result i32)
(br_table 3 2 1 0 (i32.const 42) (i32.const 0))
)
)
)
)
(func (result i32)
(block (result i32)
(br_table 0 0 1 1 (i32.const 42) (i32.const 0))
)
)
(func (result i32)
(block (result i32)
(br_table 1 1 0 0 (i32.const 42) (i32.const 0))
)
)
)

View File

@@ -0,0 +1,14 @@
(module
(func $main
(v128.const i32x4 1 2 3 4)
(v128.const i32x4 1 2 3 4)
(call $add)
drop
)
(func $add (param $a v128) (param $b v128) (result v128)
(local.get $a)
(local.get $b)
(i32x4.add)
)
(start $main)
)

View File

@@ -0,0 +1,10 @@
(module
(func $main (local i32)
(set_local 0 (i32.const 0))
(drop (call $inc))
)
(func $inc (result i32)
(i32.const 1)
)
(start $main)
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
(module
;; Iterative factorial without locals.
(func $pick0 (param i64) (result i64 i64)
(get_local 0) (get_local 0)
)
(func $pick1 (param i64 i64) (result i64 i64 i64)
(get_local 0) (get_local 1) (get_local 0)
)
(func (export "fac-ssa") (param i64) (result i64)
(i64.const 1) (get_local 0)
(loop $l (param i64 i64) (result i64)
(call $pick1) (call $pick1) (i64.mul)
(call $pick1) (i64.const 1) (i64.sub)
(call $pick0) (i64.const 0) (i64.gt_u)
(br_if $l)
(drop) (return)
)
)
)

View File

@@ -0,0 +1,22 @@
(module
(memory 1)
(func $main (local i32 i32 i32 i32)
(set_local 0 (i32.const 0))
(set_local 1 (i32.const 1))
(set_local 2 (i32.const 1))
(set_local 3 (i32.const 0))
(block
(loop
(br_if 1 (i32.gt_s (get_local 0) (i32.const 5)))
(set_local 3 (get_local 2))
(set_local 2 (i32.add (get_local 2) (get_local 1)))
(set_local 1 (get_local 3))
(set_local 0 (i32.add (get_local 0) (i32.const 1)))
(br 0)
)
)
(i32.store (i32.const 0) (get_local 2))
)
(start $main)
(data (i32.const 0) "0000")
)

View File

@@ -0,0 +1,8 @@
(module
(global $x (mut i32) (i32.const 4))
(memory 1)
(func $main (local i32)
(i32.store (i32.const 0) (get_global $x))
)
(start $main)
)

View File

@@ -0,0 +1,7 @@
(module
(type $ft (func (param v128) (result v128)))
(func $foo (export "foo") (param i32) (param v128) (result v128)
(call_indirect (type $ft) (local.get 1) (local.get 0))
)
(table (;0;) 23 23 anyfunc)
)

View File

@@ -0,0 +1,7 @@
(module
(type $ft (func (param f32) (result i32)))
(func $foo (export "foo") (param i32 f32) (result i32)
(call_indirect (type $ft) (get_local 1) (get_local 0))
)
(table (;0;) 23 23 anyfunc)
)

View File

@@ -0,0 +1,12 @@
;; An unreachable `if` means that the consequent, alternative, and following
;; block are also unreachable.
(module
(func (param i32) (result i32)
unreachable
if ;; label = @2
nop
else
nop
end
i32.const 0))

View File

@@ -0,0 +1,12 @@
;; Reachable `if` head and reachable consequent and alternative means that the
;; following block is also reachable.
(module
(func (param i32) (result i32)
local.get 0
if ;; label = @2
nop
else
nop
end
i32.const 0))

View File

@@ -0,0 +1,12 @@
;; Reachable `if` head and unreachable consequent and reachable alternative
;; means that the following block is also reachable.
(module
(func (param i32) (result i32)
local.get 0
if
unreachable
else
nop
end
i32.const 0))

View File

@@ -0,0 +1,12 @@
;; Reachable `if` head and consequent and unreachable alternative means that the
;; following block is also reachable.
(module
(func (param i32) (result i32)
local.get 0
if
nop
else
unreachable
end
i32.const 0))

View File

@@ -0,0 +1,12 @@
;; Reachable `if` head and unreachable consequent and alternative means that the
;; following block is unreachable.
(module
(func (param i32) (result i32)
local.get 0
if
unreachable
else
unreachable
end
i32.const 0))

View File

@@ -0,0 +1,14 @@
;; Reachable `if` head and unreachable consequent and alternative, but with a
;; branch out of the consequent, means that the following block is reachable.
(module
(func (param i32 i32) (result i32)
local.get 0
if
local.get 1
br_if 0
unreachable
else
unreachable
end
i32.const 0))

View File

@@ -0,0 +1,14 @@
;; Reachable `if` head and unreachable consequent and alternative, but with a
;; branch out of the alternative, means that the following block is reachable.
(module
(func (param i32 i32) (result i32)
local.get 0
if
unreachable
else
local.get 1
br_if 0
unreachable
end
i32.const 0))

View File

@@ -0,0 +1,18 @@
(module
(type (;0;) (func (param i32 i32) (result f64)))
(func $main (type 0) (param i32 i32) (result f64)
f64.const 1.0
local.get 0
local.get 1
if (param i32) ;; label = @2
i64.load16_s align=1
drop
else
unreachable
end)
(table (;0;) 63 255 funcref)
(memory (;0;) 13 16)
(export "t1" (table 0))
(export "m1" (memory 0))
(export "main" (func $main))
(export "memory" (memory 0)))

View File

@@ -0,0 +1,41 @@
(module
(type (;0;) (func (param i32)))
(func $main (type 0) (param i32)
i32.const 35
loop (param i32) ;; label = @1
local.get 0
if (param i32) ;; label = @2
i64.load16_s align=1
unreachable
unreachable
unreachable
unreachable
unreachable
local.get 0
unreachable
unreachable
i64.load8_u offset=11789
unreachable
else
i32.popcnt
local.set 0
return
unreachable
end
unreachable
unreachable
nop
f32.lt
i32.store8 offset=82
unreachable
end
unreachable
unreachable
unreachable
unreachable)
(table (;0;) 63 255 funcref)
(memory (;0;) 13 16)
(export "t1" (table 0))
(export "m1" (memory 0))
(export "main" (func $main))
(export "memory" (memory 0)))

View File

@@ -0,0 +1,11 @@
(module
(memory 1)
(func $main (local i32)
(i32.store (i32.const 0) (i32.const 0x0))
(if (i32.load (i32.const 0))
(then (i32.store (i32.const 0) (i32.const 0xa)))
(else (i32.store (i32.const 0) (i32.const 0xb))))
)
(start $main)
(data (i32.const 0) "0000")
)

View File

@@ -0,0 +1,3 @@
(module
(func (export "i64.dup") (param i64) (result i64 i64)
(get_local 0) (get_local 0)))

View File

@@ -0,0 +1,6 @@
(module
(func (export "multiBlock") (param i64 i32) (result i32 i64 f64)
(local.get 1)
(local.get 0)
(block (param i32 i64) (result i32 i64 f64)
(f64.const 1234.5))))

View File

@@ -0,0 +1,10 @@
(module
(func (export "f") (param i64 i32) (result i64 i64)
(local.get 0)
(local.get 1)
;; If with else. Fewer params than results.
(if (param i64) (result i64 i64)
(then
(i64.const -1))
(else
(i64.const -2)))))

View File

@@ -0,0 +1,7 @@
(module
(func (export "multiLoop") (param i64) (result i64 i64)
(local.get 0)
;; Fewer params than results.
(loop (param i64) (result i64 i64)
i64.const 42
return)))

View File

@@ -0,0 +1,9 @@
(module
(func (export "multiLoop") (param i64 i64 i64) (result i64 i64)
(local.get 2)
(local.get 1)
(local.get 0)
;; More params than results.
(loop (param i64 i64 i64) (result i64 i64)
drop
return)))

View File

@@ -0,0 +1,10 @@
(module
(func (export "as-if-then") (param i32 i32) (result i32)
(block (result i32)
(if (result i32) (local.get 0)
(then (br 1 (i32.const 3)))
(else (local.get 1))
)
)
)
)

View File

@@ -0,0 +1,10 @@
(module
(func (export "as-if-else") (param i32 i32) (result i32)
(block (result i32)
(if (result i32) (local.get 0)
(then (local.get 1))
(else (br 1 (i32.const 4)))
)
)
)
)

View File

@@ -0,0 +1,22 @@
(module
(func (export "large-sig")
(param i32 i64 f32 f32 i32 f64 f32 i32 i32 i32 f32 f64 f64 f64 i32 i32 f32)
(result f64 f32 i32 i32 i32 i64 f32 i32 i32 f32 f64 f64 i32 f32 i32 f64)
(local.get 5)
(local.get 2)
(local.get 0)
(local.get 8)
(local.get 7)
(local.get 1)
(local.get 3)
(local.get 9)
(local.get 4)
(local.get 6)
(local.get 13)
(local.get 11)
(local.get 15)
(local.get 16)
(local.get 14)
(local.get 12)
)
)

View File

@@ -0,0 +1,9 @@
(module
(func (export "param") (param i32) (result i32)
(i32.const 1)
(if (param i32) (result i32) (local.get 0)
(then (i32.const 2) (i32.add))
(else (i32.const -2) (i32.add))
)
)
)

View File

@@ -0,0 +1,26 @@
(module
(func $main (type 0) (param i32 i32 i32) (result i32)
i32.const 0
i32.const 0
i32.const 0
i32.const 0
i32.const 0
if (param i32 i32 i32) (result i32) ;; label = @1
br 0 (;@1;)
else
call $main
end
i32.const 0
i32.const 0
if (param i32 i32 i32) (result i32) ;; label = @1
drop
drop
else
drop
drop
end
)
(export "main" (func $main)))

View File

@@ -0,0 +1,6 @@
(module
(func (export "multiLoop") (param i64 i64) (result i64 i64)
(local.get 1)
(local.get 0)
(loop (param i64 i64) (result i64 i64)
return)))

View File

@@ -0,0 +1,13 @@
(module
(func (export "multiIf") (param i32 i64 i64) (result i64 i64)
(local.get 2)
(local.get 1)
(local.get 0)
(if (param i64 i64) (result i64 i64)
(then return)
;; Hits the code path for an `else` after a block that ends unreachable.
(else
(drop)
(drop)
(i64.const 0)
(i64.const 0)))))

View File

@@ -0,0 +1,13 @@
(module
(func (export "multiIf2") (param i32 i64 i64) (result i64 i64)
(local.get 2)
(local.get 1)
(local.get 0)
(if (param i64 i64) (result i64 i64)
(then
i64.add
i64.const 1)
;; Hits the code path for an `else` after a block that does not end unreachable.
(else
i64.sub
i64.const 2))))

View File

@@ -0,0 +1,11 @@
(module
(func (export "foo")
i32.const 1
i64.const 2
;; More params than results.
(block (param i32 i64) (result i32)
drop
)
drop
)
)

View File

@@ -0,0 +1,11 @@
(module
(func (export "foo")
i32.const 1
;; Fewer params than results.
(block (param i32) (result i32 i64)
i64.const 2
)
drop
drop
)
)

View File

@@ -0,0 +1,9 @@
(module
(func (export "f") (param i64 i32) (result i64)
(local.get 0)
(local.get 1)
;; If with no else. Same number of params and results.
(if (param i64) (result i64)
(then
(drop)
(i64.const -1)))))

View File

@@ -0,0 +1,12 @@
(module
(func (export "f") (param i64 i32) (result i64)
(local.get 0)
(local.get 1)
;; If with else. Same number of params and results.
(if (param i64) (result i64)
(then
(drop)
(i64.const -1))
(else
(drop)
(i64.const -2)))))

View File

@@ -0,0 +1,15 @@
(module
(func (export "f") (param i64 i32) (result i64)
(local.get 0)
(local.get 1)
(local.get 1)
;; If with else. More params than results.
(if (param i64 i32) (result i64)
(then
(drop)
(drop)
(i64.const -1))
(else
(drop)
(drop)
(i64.const -2)))))

View File

@@ -0,0 +1,11 @@
(module
(func (result externref)
(ref.null extern)
)
(func (result externref)
(block (result externref)
(ref.null extern)
)
)
)

View File

@@ -0,0 +1,12 @@
(module
(data $passive "this is a passive data segment")
(memory 0)
(func (export "init") (param i32 i32 i32)
local.get 0 ;; dst
local.get 1 ;; src
local.get 2 ;; cnt
memory.init $passive)
(func (export "drop")
data.drop $passive))

View File

@@ -0,0 +1,15 @@
(module
(memory (export "mem") 1 1)
(func (export "runif") (param $cond i32)
i32.const 48
(v128.load (i32.const 0))
(v128.load (i32.const 16))
(if (param v128) (param v128) (result v128 v128)
(local.get $cond)
(then i64x2.add
(v128.load (i32.const 32)))
(else i32x4.sub
(v128.load (i32.const 0))))
i16x8.mul
v128.store)
)

View File

@@ -0,0 +1,51 @@
(module
(type (;0;) (func (result v128 v128 v128)))
(func $main1 (type 0) (result v128 v128 v128)
call $main1
i8x16.add
call $main1
i8x16.ge_u
i16x8.ne
i32.const 13
br_if 0 (;@0;)
i32.const 43
br_if 0 (;@0;)
i32.const 13
br_if 0 (;@0;)
i32.const 87
select
unreachable
i32.const 0
br_if 0 (;@0;)
i32.const 13
br_if 0 (;@0;)
i32.const 43
br_if 0 (;@0;)
)
(export "main1" (func $main1))
(func $main2 (type 0) (result v128 v128 v128)
call $main2
i8x16.add
call $main2
i8x16.ge_u
i16x8.ne
i32.const 13
br_if 0 (;@0;)
i32.const 43
br_if 0 (;@0;)
i32.const 13
br_if 0 (;@0;)
i32.const 87
select (result v128)
unreachable
i32.const 0
br_if 0 (;@0;)
i32.const 13
br_if 0 (;@0;)
i32.const 43
br_if 0 (;@0;)
)
(export "main2" (func $main2))
)

View File

@@ -0,0 +1,12 @@
(module
(func $imported (import "env" "f") (param i32) (result i32))
(func $local (result externref externref funcref funcref)
global.get 0
global.get 1
global.get 2
global.get 3)
(global (export "externref-imported") externref (ref.null extern))
(global (export "externref-local") externref (ref.null extern))
(global (export "funcref-imported") funcref (ref.func $imported))
(global (export "funcref-local") funcref (ref.func $local)))

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
(module
(func $untyped-select (result i32)
i32.const 42
i32.const 24
i32.const 1
select)
(func $typed-select-1 (result externref)
ref.null extern
ref.null extern
i32.const 1
select (result externref))
(func $typed-select-2 (param externref) (result externref)
ref.null extern
local.get 0
i32.const 1
select (result externref))
)

View File

@@ -0,0 +1,29 @@
(module
(func $test_splat (result i32)
i32.const 42
i32x4.splat
i32x4.extract_lane 0
)
(func $test_insert_lane (result i32)
v128.const i64x2 0 0
i32.const 99
i32x4.replace_lane 1
i32x4.extract_lane 1
)
(func $test_const (result i32)
v128.const i32x4 1 2 3 4
i32x4.extract_lane 3
)
(func $test_locals (local i32 v128)
local.get 0
i32x4.splat
local.set 1
)
(export "test_splat" (func $test_splat))
(export "test_insert_lane" (func $test_insert_lane))
(export "test_const" (func $test_const))
)

View File

@@ -0,0 +1,22 @@
(module $n
(table $t (import "m" "t") 6 funcref)
(func $i (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 3))
(func $j (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 4))
(func $k (param i32 i32 i32 i32 i32 i32) (result i32) (local.get 5))
(table $u (export "u") funcref (elem $i $j $k $i $j $k))
(func (export "copy_to_t_from_u") (param i32 i32 i32 i32) (result i32)
local.get 0
local.get 1
local.get 2
local.get 3
table.copy $t $u)
(func (export "copy_to_u_from_t") (param i32 i32 i32 i32) (result i32)
local.get 0
local.get 1
local.get 2
local.get 3
table.copy $u $t))

View File

@@ -0,0 +1,77 @@
(module
(type (;0;) (func (param i32 i64 f64) (result f64)))
(type (;1;) (func))
(type (;2;) (func (result f32)))
(type (;3;) (func (result f64)))
(type (;4;) (func (param f64 f64) (result f64)))
(type (;5;) (func (result i32)))
(func (result i32)
block (result i32)
unreachable
end
block
end
i32.clz
)
(func (result i32)
loop (result i32)
unreachable
end
block
end
i32.clz
)
(func (;0;) (type 5) (result i32)
nop
block (result i32) ;; label = @1
block ;; label = @2
block ;; label = @3
nop
block ;; label = @4
i32.const 1
if ;; label = @5
nop
block ;; label = @6
nop
nop
loop (result i32) ;; label = @7
nop
block (result i32) ;; label = @8
nop
nop
block (result i32) ;; label = @9
nop
unreachable
end
end
end
block (result i32) ;; label = @7
block ;; label = @8
nop
end
i32.const 0
end
br_if 5 (;@1;)
drop
end
else
nop
end
nop
end
end
end
unreachable
end)
(func
block (result i32)
block (result i32)
i32.const 1
br 1
end
end
drop
)
(table (;0;) 16 anyfunc)
(elem (i32.const 0))
)

View File

@@ -0,0 +1,10 @@
(module
(memory 1)
(func $main (param i32)
(if
(get_local 0)
(then (return))
(else (unreachable))
)
)
)