diff options
author | Alon Zakai <azakai@google.com> | 2022-08-24 11:40:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-24 11:40:43 -0700 |
commit | d5e17e7bbe0901606b0892dfe3fca88d84bf6f82 (patch) | |
tree | 9112bc454efc207773140acb4a0b61bea3137c1b /test | |
parent | cee1c8681b3ae6bf5836999bd4df3d1d0997a138 (diff) | |
download | binaryen-d5e17e7bbe0901606b0892dfe3fca88d84bf6f82.tar.gz binaryen-d5e17e7bbe0901606b0892dfe3fca88d84bf6f82.tar.bz2 binaryen-d5e17e7bbe0901606b0892dfe3fca88d84bf6f82.zip |
[TNH Fuzzing] Fix some equality checks that ignored effects (#4951)
Fuzzing with TrapsNeverHappen found a bug, and then reading similar code
I found another, where we check structural equality but ignored effects. Some
things look equal but may have different values at runtime:
(foo
(call $x)
(call $y)
)
The arms are identical structurally but due to side effects may not be identical
in value.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/optimize-instructions-ignore-traps.wast | 28 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions.wast | 19 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/lit/passes/optimize-instructions-ignore-traps.wast b/test/lit/passes/optimize-instructions-ignore-traps.wast index cca6061f4..a199f1b46 100644 --- a/test/lit/passes/optimize-instructions-ignore-traps.wast +++ b/test/lit/passes/optimize-instructions-ignore-traps.wast @@ -5,8 +5,13 @@ (module ;; CHECK: (type $0 (func (param i32 i32) (result i32))) (type $0 (func (param i32 i32) (result i32))) + ;; CHECK: (import "a" "b" (func $get-i32 (result i32))) + ;; CHECK: (memory $0 0) (memory $0 0) + + (import "a" "b" (func $get-i32 (result i32))) + ;; CHECK: (func $conditionals (param $0 i32) (param $1 i32) (result i32) ;; CHECK-NEXT: (local $2 i32) ;; CHECK-NEXT: (local $3 i32) @@ -732,6 +737,19 @@ ;; CHECK-NEXT: (local.get $src) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (memory.copy + ;; CHECK-NEXT: (call $get-i32) + ;; CHECK-NEXT: (call $get-i32) + ;; CHECK-NEXT: (local.get $sz) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (block + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (call $get-i32) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (call $get-i32) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) (func $optimize-bulk-memory-copy (param $dst i32) (param $src i32) (param $sz i32) (memory.copy ;; nop @@ -745,6 +763,16 @@ (local.get $src) (i32.const 0) ) + (memory.copy ;; not a nop as the runtime dst/src may differ + (call $get-i32) + (call $get-i32) + (local.get $sz) + ) + (memory.copy ;; as above, but with a size of 0. the calls must remain. + (call $get-i32) + (call $get-i32) + (i32.const 0) + ) ) ;; CHECK: (func $optimize-bulk-memory-fill (param $dst i32) (param $val i32) (param $sz i32) diff --git a/test/lit/passes/optimize-instructions.wast b/test/lit/passes/optimize-instructions.wast index 336bb63ae..73e7fd286 100644 --- a/test/lit/passes/optimize-instructions.wast +++ b/test/lit/passes/optimize-instructions.wast @@ -5,6 +5,10 @@ (memory 0) ;; CHECK: (type $0 (func (param i32 i64))) (type $0 (func (param i32 i64))) + + ;; CHECK: (import "a" "b" (func $get-f64 (result f64))) + (import "a" "b" (func $get-f64 (result f64))) + ;; CHECK: (func $and-and (param $i1 i32) (result i32) ;; CHECK-NEXT: (i32.and ;; CHECK-NEXT: (local.get $i1) @@ -13238,6 +13242,14 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (f64.abs + ;; CHECK-NEXT: (f64.mul + ;; CHECK-NEXT: (call $get-f64) + ;; CHECK-NEXT: (call $get-f64) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (f64.div ;; CHECK-NEXT: (local.get $x0) ;; CHECK-NEXT: (local.get $x0) @@ -13378,6 +13390,13 @@ (local.get $y0) ) )) + ;; this one cannot be optimized as the runtime values may differ + (drop (f64.abs + (f64.mul + (call $get-f64) + (call $get-f64) + ) + )) ;; abs(x / x) ==> x / x (drop (f64.abs |