diff options
author | Alon Zakai <azakai@google.com> | 2020-12-11 08:32:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 08:32:02 -0800 |
commit | 290147d8d43a7448d68939ec711b524ba4fb3fbd (patch) | |
tree | e5403fd0fe2d3008186f79240a5ec9a1518615c5 /test | |
parent | e16cf5818de5a6e37ffcbce0bcde320290d9f9f1 (diff) | |
download | binaryen-290147d8d43a7448d68939ec711b524ba4fb3fbd.tar.gz binaryen-290147d8d43a7448d68939ec711b524ba4fb3fbd.tar.bz2 binaryen-290147d8d43a7448d68939ec711b524ba4fb3fbd.zip |
[GC] Fix Array optimization issues (#3438)
Precompute still tried to precompute a reference because the check was
not in the topmost place.
Also we truncated i8/i16 values, but did not extend them properly. That
was also an issue with structs.
The new test replaces the old one by moving from -O1 to -Oz (which
runs more opts, and would have noticed this earlier), and adds array
operations too, including sign extends.
Diffstat (limited to 'test')
-rw-r--r-- | test/passes/O1_fuzz-exec_all-features.txt | 52 | ||||
-rw-r--r-- | test/passes/O1_fuzz-exec_all-features.wast | 37 | ||||
-rw-r--r-- | test/passes/Oz_fuzz-exec_all-features.txt | 109 | ||||
-rw-r--r-- | test/passes/Oz_fuzz-exec_all-features.wast | 70 |
4 files changed, 179 insertions, 89 deletions
diff --git a/test/passes/O1_fuzz-exec_all-features.txt b/test/passes/O1_fuzz-exec_all-features.txt deleted file mode 100644 index 522943d69..000000000 --- a/test/passes/O1_fuzz-exec_all-features.txt +++ /dev/null @@ -1,52 +0,0 @@ -[fuzz-exec] calling structs -[LoggingExternalInterface logging 0] -[LoggingExternalInterface logging 42] -[LoggingExternalInterface logging 100] -[LoggingExternalInterface logging 100] -(module - (type ${i32} (struct (field i32))) - (type $none_=>_none (func)) - (type $i32_=>_none (func (param i32))) - (import "fuzzing-support" "log-i32" (func $log (param i32))) - (export "structs" (func $0)) - (func $0 - (local $0 (ref null ${i32})) - (call $log - (struct.get ${i32} 0 - (local.tee $0 - (struct.new_default_with_rtt ${i32} - (rtt.canon ${i32}) - ) - ) - ) - ) - (struct.set ${i32} 0 - (local.get $0) - (i32.const 42) - ) - (call $log - (struct.get ${i32} 0 - (local.get $0) - ) - ) - (struct.set ${i32} 0 - (local.get $0) - (i32.const 100) - ) - (call $log - (struct.get ${i32} 0 - (local.get $0) - ) - ) - (call $log - (struct.get ${i32} 0 - (local.get $0) - ) - ) - ) -) -[fuzz-exec] calling structs -[LoggingExternalInterface logging 0] -[LoggingExternalInterface logging 42] -[LoggingExternalInterface logging 100] -[LoggingExternalInterface logging 100] diff --git a/test/passes/O1_fuzz-exec_all-features.wast b/test/passes/O1_fuzz-exec_all-features.wast deleted file mode 100644 index 0740e60e7..000000000 --- a/test/passes/O1_fuzz-exec_all-features.wast +++ /dev/null @@ -1,37 +0,0 @@ -(module - (type $struct (struct i32)) - (import "fuzzing-support" "log-i32" (func $log (param i32))) - (func "structs" - (local $x (ref null $struct)) - (local $y (ref null $struct)) - (local.set $x - (struct.new_default_with_rtt $struct - (rtt.canon $struct) - ) - ) - ;; The value is initialized to 0 - (call $log - (struct.get $struct 0 (local.get $x)) - ) - ;; Assigning a value works - (struct.set $struct 0 - (local.get $x) - (i32.const 42) - ) - (call $log - (struct.get $struct 0 (local.get $x)) - ) - ;; References are references, so writing to one's value affects the other's - (local.set $y (local.get $x)) - (struct.set $struct 0 - (local.get $y) - (i32.const 100) - ) - (call $log - (struct.get $struct 0 (local.get $x)) - ) - (call $log - (struct.get $struct 0 (local.get $y)) - ) - ) -) diff --git a/test/passes/Oz_fuzz-exec_all-features.txt b/test/passes/Oz_fuzz-exec_all-features.txt new file mode 100644 index 000000000..0663a3351 --- /dev/null +++ b/test/passes/Oz_fuzz-exec_all-features.txt @@ -0,0 +1,109 @@ +[fuzz-exec] calling structs +[LoggingExternalInterface logging 0] +[LoggingExternalInterface logging 42] +[LoggingExternalInterface logging 100] +[LoggingExternalInterface logging 100] +[fuzz-exec] calling arrays +[LoggingExternalInterface logging 50] +[LoggingExternalInterface logging 42] +[LoggingExternalInterface logging 128] +[LoggingExternalInterface logging -128] +[LoggingExternalInterface logging 42] +(module + (type ${i32} (struct (field i32))) + (type $none_=>_none (func)) + (type $[mut:i8] (array (mut i8))) + (type $i32_=>_none (func (param i32))) + (import "fuzzing-support" "log-i32" (func $log (param i32))) + (export "structs" (func $0)) + (export "arrays" (func $1)) + (func $0 (; has Stack IR ;) + (local $0 (ref null ${i32})) + (call $log + (struct.get ${i32} 0 + (local.tee $0 + (struct.new_default_with_rtt ${i32} + (rtt.canon ${i32}) + ) + ) + ) + ) + (struct.set ${i32} 0 + (local.get $0) + (i32.const 42) + ) + (call $log + (struct.get ${i32} 0 + (local.get $0) + ) + ) + (struct.set ${i32} 0 + (local.get $0) + (i32.const 100) + ) + (call $log + (struct.get ${i32} 0 + (local.get $0) + ) + ) + (call $log + (struct.get ${i32} 0 + (local.get $0) + ) + ) + ) + (func $1 (; has Stack IR ;) + (local $0 (ref null $[mut:i8])) + (call $log + (array.len $[mut:i8] + (local.tee $0 + (array.new_with_rtt $[mut:i8] + (rtt.canon $[mut:i8]) + (i32.const 50) + (i32.const 42) + ) + ) + ) + ) + (call $log + (array.get_u $[mut:i8] + (local.get $0) + (i32.const 10) + ) + ) + (array.set $[mut:i8] + (local.get $0) + (i32.const 10) + (i32.const 65408) + ) + (call $log + (array.get_u $[mut:i8] + (local.get $0) + (i32.const 10) + ) + ) + (call $log + (array.get_s $[mut:i8] + (local.get $0) + (i32.const 10) + ) + ) + (call $log + (array.get_s $[mut:i8] + (local.get $0) + (i32.const 20) + ) + ) + ) +) +[fuzz-exec] calling structs +[LoggingExternalInterface logging 0] +[LoggingExternalInterface logging 42] +[LoggingExternalInterface logging 100] +[LoggingExternalInterface logging 100] +[fuzz-exec] calling arrays +[LoggingExternalInterface logging 50] +[LoggingExternalInterface logging 42] +[LoggingExternalInterface logging 128] +[LoggingExternalInterface logging -128] +[LoggingExternalInterface logging 42] diff --git a/test/passes/Oz_fuzz-exec_all-features.wast b/test/passes/Oz_fuzz-exec_all-features.wast new file mode 100644 index 000000000..d32ee0c19 --- /dev/null +++ b/test/passes/Oz_fuzz-exec_all-features.wast @@ -0,0 +1,70 @@ +(module + (type $struct (struct i32)) + (type $bytes (array (mut i8))) + (import "fuzzing-support" "log-i32" (func $log (param i32))) + (func "structs" + (local $x (ref null $struct)) + (local $y (ref null $struct)) + (local.set $x + (struct.new_default_with_rtt $struct + (rtt.canon $struct) + ) + ) + ;; The value is initialized to 0 + ;; Note: -Oz will optimize all these to constants thanks to Precompute + (call $log + (struct.get $struct 0 (local.get $x)) + ) + ;; Assigning a value works + (struct.set $struct 0 + (local.get $x) + (i32.const 42) + ) + (call $log + (struct.get $struct 0 (local.get $x)) + ) + ;; References are references, so writing to one's value affects the other's + (local.set $y (local.get $x)) + (struct.set $struct 0 + (local.get $y) + (i32.const 100) + ) + (call $log + (struct.get $struct 0 (local.get $x)) + ) + (call $log + (struct.get $struct 0 (local.get $y)) + ) + ) + (func "arrays" + (local $x (ref null $bytes)) + (local.set $x + (array.new_with_rtt $bytes + (rtt.canon $bytes) + (i32.const 50) ;; size + (i32.const 42) ;; value to splat into the array + ) + ) + ;; The length should be 50 + (call $log + (array.len $bytes (local.get $x)) + ) + ;; The value should be 42 + (call $log + (array.get_u $bytes (local.get $x) (i32.const 10)) + ) + ;; Write a value that will be truncated into an i8 + (array.set $bytes (local.get $x) (i32.const 10) (i32.const 0xff80)) + ;; The value should be 0x80 (-128 or 128 depending on signed/unsigned) + (call $log + (array.get_u $bytes (local.get $x) (i32.const 10)) + ) + (call $log + (array.get_s $bytes (local.get $x) (i32.const 10)) + ) + ;; Other items than the one at index 10 are unaffected. + (call $log + (array.get_s $bytes (local.get $x) (i32.const 20)) + ) + ) +) |