diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-08-01 08:06:04 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-01 08:06:04 -0700 |
commit | 5a07a930ad51003411b2bc827ea9bf08728ecc5a (patch) | |
tree | 7a599caa2977464e4b056c59457d17c4d7e1bd91 /test | |
parent | 76751bf1f9df4eb2ee6c216744af9ed1e097132e (diff) | |
parent | 44154e3d0895e2f5688861f0bc8d62af71ee6b6d (diff) | |
download | binaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.tar.gz binaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.tar.bz2 binaryen-5a07a930ad51003411b2bc827ea9bf08728ecc5a.zip |
Merge pull request #1116 from WebAssembly/fuzz
Fuzz fixes
Diffstat (limited to 'test')
-rw-r--r-- | test/passes/fuzz-exec_O.txt | 25 | ||||
-rw-r--r-- | test/passes/fuzz-exec_O.wast | 23 | ||||
-rw-r--r-- | test/passes/merge-blocks.txt | 32 | ||||
-rw-r--r-- | test/passes/merge-blocks.wast | 19 | ||||
-rw-r--r-- | test/passes/optimize-instructions.txt | 73 | ||||
-rw-r--r-- | test/passes/optimize-instructions.wast | 65 | ||||
-rw-r--r-- | test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.txt | 70 | ||||
-rw-r--r-- | test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.wast | 64 | ||||
-rw-r--r-- | test/untaken-br_if.wast | 14 | ||||
-rw-r--r-- | test/untaken-br_if.wast.from-wast | 16 | ||||
-rw-r--r-- | test/untaken-br_if.wast.fromBinary | 27 | ||||
-rw-r--r-- | test/untaken-br_if.wast.fromBinary.noDebugInfo | 27 |
12 files changed, 441 insertions, 14 deletions
diff --git a/test/passes/fuzz-exec_O.txt b/test/passes/fuzz-exec_O.txt new file mode 100644 index 000000000..f5f8583a3 --- /dev/null +++ b/test/passes/fuzz-exec_O.txt @@ -0,0 +1,25 @@ +[fuzz-exec] 2 results noted +(module + (type $0 (func (result i64))) + (type $1 (func (result i32))) + (memory $0 1 1) + (export "func_0" (func $func_0)) + (export "func_1" (func $func_1)) + (func $func_0 (type $0) (result i64) + (block $label$0 (result i64) + (br_if $label$0 + (i64.const 1234) + (i32.load16_s offset=22 align=1 + (i32.const -1) + ) + ) + ) + ) + (func $func_1 (type $1) (result i32) + (i32.load16_s offset=22 align=1 + (i32.const -1) + ) + ) +) +[fuzz-exec] 2 results noted +[fuzz-exec] results match diff --git a/test/passes/fuzz-exec_O.wast b/test/passes/fuzz-exec_O.wast new file mode 100644 index 000000000..3d03de714 --- /dev/null +++ b/test/passes/fuzz-exec_O.wast @@ -0,0 +1,23 @@ +(module + (memory $0 1 1) + (export "func_0" (func $func_0)) + (export "func_1" (func $func_1)) + (func $func_0 (result i64) + (block $label$0 (result i64) + (loop $label$1 (result i64) + (br_if $label$0 + (i64.const 1234) + (i32.load16_s offset=22 align=1 + (i32.const -1) + ) + ) + ) + ) + ) + (func $func_1 (result i32) + (i32.load16_s offset=22 align=1 + (i32.const -1) + ) + ) +) + diff --git a/test/passes/merge-blocks.txt b/test/passes/merge-blocks.txt index 545438b1d..b972a6421 100644 --- a/test/passes/merge-blocks.txt +++ b/test/passes/merge-blocks.txt @@ -78,10 +78,15 @@ ) (func $drop-unreachable-br_if (type $2) (result i32) (block $label$0 (result i32) - (block $label$2 - (drop - (br $label$0 - (i32.const 538976371) + (drop + (block $label$2 + (drop + (br_if $label$2 + (br $label$0 + (i32.const 538976371) + ) + (i32.const 1918987552) + ) ) ) ) @@ -100,4 +105,23 @@ ) ) ) + (func $br-goes-away-label2-becomes-unreachable (type $0) + (block $block + (drop + (block $label$1 (result i32) + (block $label$2 + (drop + (br_if $label$1 + (unreachable) + (i32.eqz + (br $label$2) + ) + ) + ) + ) + (i32.const 1) + ) + ) + ) + ) ) diff --git a/test/passes/merge-blocks.wast b/test/passes/merge-blocks.wast index e998060c4..81b70d1b5 100644 --- a/test/passes/merge-blocks.wast +++ b/test/passes/merge-blocks.wast @@ -82,5 +82,24 @@ ) ) ) + (func $br-goes-away-label2-becomes-unreachable + (block + (drop + (block $label$1 (result i32) + (block $label$2 + (drop + (br_if $label$1 + (unreachable) + (i32.eqz + (br $label$2) + ) + ) + ) + ) + (i32.const 1) + ) + ) + ) + ) ) diff --git a/test/passes/optimize-instructions.txt b/test/passes/optimize-instructions.txt index 604c9c3ea..a399a9096 100644 --- a/test/passes/optimize-instructions.txt +++ b/test/passes/optimize-instructions.txt @@ -6,6 +6,7 @@ (type $4 (func (param i32 i32))) (type $5 (func (param i32))) (type $6 (func (param i32 i32) (result i32))) + (type $7 (func (param i64) (result i64))) (memory $0 0) (export "load-off-2" (func $load-off-2)) (func $f (type $0) (param $i1 i32) (param $i2 i64) @@ -462,16 +463,16 @@ (i32.const 4) (get_local $0) ) - (i32.store - (i32.const 0) + (i32.store offset=2 + (i32.const -2) (get_local $0) ) (i32.store (i32.const 25) (get_local $0) ) - (i32.store - (i32.const -23) + (i32.store offset=2 + (i32.const -25) (get_local $0) ) (drop @@ -734,7 +735,7 @@ (i32.shr_s (i32.shl (i32.const 32) - (i32.const 59) + (i32.const 27) ) (i32.const 24) ) @@ -805,7 +806,7 @@ (i32.const -1) (i32.const 2147483647) ) - (i32.const 32) + (i32.const 31) ) ) (drop @@ -1083,19 +1084,19 @@ (drop (i32.shl (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop (i32.shr_s (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop (i32.shr_u (get_local $0) - (i32.const 211) + (i32.const 19) ) ) (drop @@ -2006,4 +2007,58 @@ (i32.const 1) ) ) + (func $neg-shifts-and-255 (type $2) (result i32) + (i32.and + (i32.shr_u + (i32.const -99) + (i32.const -32) + ) + (i32.const 255) + ) + ) + (func $neg-shifts-and-255-b (type $2) (result i32) + (i32.and + (i32.shl + (i32.const -2349025) + (i32.const -32) + ) + (i32.const 255) + ) + ) + (func $shifts-square-overflow (type $3) (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 65535) + ) + (i32.const 32767) + ) + ) + (func $shifts-square-no-overflow-small (type $3) (param $x i32) (result i32) + (i32.shr_u + (get_local $x) + (i32.const 9) + ) + ) + (func $shifts-square-overflow-64 (type $7) (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 65535) + ) + (i64.const 64767) + ) + ) + (func $shifts-square-no-overflow-small-64 (type $7) (param $x i64) (result i64) + (i64.shr_u + (get_local $x) + (i64.const 9) + ) + ) + (func $shifts-square-unreachable (type $3) (param $x i32) (result i32) + (i32.shr_u + (unreachable) + (i32.const 9) + ) + ) ) diff --git a/test/passes/optimize-instructions.wast b/test/passes/optimize-instructions.wast index cf8275412..8362453e9 100644 --- a/test/passes/optimize-instructions.wast +++ b/test/passes/optimize-instructions.wast @@ -842,7 +842,7 @@ (i32.const -1) (i32.const 2147483647) ) - (i32.const 32) + (i32.const 31) ;; adjusted after we fixed shift computation to just look at lower 5 bits ) (i32.const 24) ) @@ -2433,4 +2433,67 @@ (i32.const 1) ) ) + (func $neg-shifts-and-255 (result i32) + (i32.and + (i32.shr_u + (i32.const -99) + (i32.const -32) ;; this shift does nothing + ) + (i32.const 255) + ) + ) + (func $neg-shifts-and-255-b (result i32) + (i32.and + (i32.shl + (i32.const -2349025) + (i32.const -32) ;; this shift does nothing + ) + (i32.const 255) + ) + ) + (func $shifts-square-overflow (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 65535) ;; 31 bits effectively + ) + (i32.const 32767) ;; also 31 bits, so two shifts that force the value into nothing for sure + ) + ) + (func $shifts-square-no-overflow-small (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (get_local $x) + (i32.const 1031) ;; 7 bits effectively + ) + (i32.const 4098) ;; 2 bits effectively + ) + ) + (func $shifts-square-overflow-64 (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 65535) ;; 63 bits effectively + ) + (i64.const 64767) ;; also 63 bits, so two shifts that force the value into nothing for sure + ) + ) + (func $shifts-square-no-overflow-small-64 (param $x i64) (result i64) + (i64.shr_u + (i64.shr_u + (get_local $x) + (i64.const 1031) ;; 7 bits effectively + ) + (i64.const 4098) ;; 2 bits effectively + ) + ) + (func $shifts-square-unreachable (param $x i32) (result i32) + (i32.shr_u + (i32.shr_u + (unreachable) + (i32.const 1031) ;; 7 bits effectively + ) + (i32.const 4098) ;; 2 bits effectively + ) + ) ) diff --git a/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.txt b/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.txt index e2c4bb786..922f64008 100644 --- a/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.txt +++ b/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.txt @@ -251,4 +251,74 @@ (get_local $5) ) ) + (func $invalidate-conditionalizeExpensiveOnBitwise (type $0) (param $0 i32) (param $1 i32) (result i32) + (if + (i32.eqz + (i32.and + (i32.lt_s + (i32.and + (i32.shr_s + (i32.shl + (i32.add + (get_local $1) + (i32.const -1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 255) + ) + (i32.const 3) + ) + (i32.ne + (tee_local $1 + (i32.const 0) + ) + (i32.const 0) + ) + ) + ) + (return + (get_local $0) + ) + ) + (return + (get_local $1) + ) + ) + (func $invalidate-conditionalizeExpensiveOnBitwise-ok (type $0) (param $0 i32) (param $1 i32) (result i32) + (if + (i32.eqz + (if (result i32) + (tee_local $1 + (i32.const 0) + ) + (i32.lt_s + (i32.and + (i32.shr_s + (i32.shl + (i32.add + (get_local $0) + (i32.const -1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 255) + ) + (i32.const 3) + ) + (i32.const 0) + ) + ) + (return + (get_local $0) + ) + ) + (return + (get_local $1) + ) + ) ) diff --git a/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.wast b/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.wast index e1215fa3f..7e8365812 100644 --- a/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.wast +++ b/test/passes/optimize-instructions_optimize-level=2_ignore-implicit-traps.wast @@ -259,5 +259,69 @@ (get_local $5) ) ) + (func $invalidate-conditionalizeExpensiveOnBitwise (param $0 i32) (param $1 i32) (result i32) + (if + (i32.eqz + (i32.and + (i32.lt_s + (i32.and + (i32.shr_s + (i32.shl + (i32.add + (get_local $1) ;; conflict with tee + (i32.const -1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 255) + ) + (i32.const 3) + ) + (i32.ne + (tee_local $1 + (i32.const 0) + ) + (i32.const 0) + ) + ) + ) + (return (get_local $0)) + ) + (return (get_local $1)) + ) + (func $invalidate-conditionalizeExpensiveOnBitwise-ok (param $0 i32) (param $1 i32) (result i32) + (if + (i32.eqz + (i32.and + (i32.lt_s + (i32.and + (i32.shr_s + (i32.shl + (i32.add + (get_local $0) ;; no conflict + (i32.const -1) + ) + (i32.const 24) + ) + (i32.const 24) + ) + (i32.const 255) + ) + (i32.const 3) + ) + (i32.ne + (tee_local $1 + (i32.const 0) + ) + (i32.const 0) + ) + ) + ) + (return (get_local $0)) + ) + (return (get_local $1)) + ) ) diff --git a/test/untaken-br_if.wast b/test/untaken-br_if.wast new file mode 100644 index 000000000..a165cf67f --- /dev/null +++ b/test/untaken-br_if.wast @@ -0,0 +1,14 @@ +(module + (func $binaryify-untaken-br_if (result f32) + (if + (i32.const 1) + (unreachable) + (block $label$1 + (br_if $label$1 + (i32.const 1) + (unreachable) + ) + ) + ) + ) +) diff --git a/test/untaken-br_if.wast.from-wast b/test/untaken-br_if.wast.from-wast new file mode 100644 index 000000000..2d6d9dd2d --- /dev/null +++ b/test/untaken-br_if.wast.from-wast @@ -0,0 +1,16 @@ +(module + (type $0 (func (result f32))) + (memory $0 0) + (func $binaryify-untaken-br_if (type $0) (result f32) + (if + (i32.const 1) + (unreachable) + (block $label$1 + (br_if $label$1 + (i32.const 1) + (unreachable) + ) + ) + ) + ) +) diff --git a/test/untaken-br_if.wast.fromBinary b/test/untaken-br_if.wast.fromBinary new file mode 100644 index 000000000..87dd9c757 --- /dev/null +++ b/test/untaken-br_if.wast.fromBinary @@ -0,0 +1,27 @@ +(module + (type $0 (func (result f32))) + (memory $0 0) + (func $binaryify-untaken-br_if (type $0) (result f32) + (if + (i32.const 1) + (block $label$0 + (unreachable) + ) + (block $label$1 + (block $label$2 + (drop + (i32.const 1) + ) + (br_if $label$2 + (unreachable) + ) + (unreachable) + (unreachable) + ) + (unreachable) + ) + ) + (unreachable) + ) +) + diff --git a/test/untaken-br_if.wast.fromBinary.noDebugInfo b/test/untaken-br_if.wast.fromBinary.noDebugInfo new file mode 100644 index 000000000..ad71cd874 --- /dev/null +++ b/test/untaken-br_if.wast.fromBinary.noDebugInfo @@ -0,0 +1,27 @@ +(module + (type $0 (func (result f32))) + (memory $0 0) + (func $0 (type $0) (result f32) + (if + (i32.const 1) + (block $label$0 + (unreachable) + ) + (block $label$1 + (block $label$2 + (drop + (i32.const 1) + ) + (br_if $label$2 + (unreachable) + ) + (unreachable) + (unreachable) + ) + (unreachable) + ) + ) + (unreachable) + ) +) + |