diff options
author | Alon Zakai <azakai@google.com> | 2020-12-09 11:17:28 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-09 11:17:28 -0800 |
commit | 823222ff566b38495327bc28b4726871b0a86b26 (patch) | |
tree | d0425f0c40d61e9085bc3a9880faa08eafd70276 /test | |
parent | 63a042e3a94df7ba3a5c9dde03990a9813fdc366 (diff) | |
download | binaryen-823222ff566b38495327bc28b4726871b0a86b26.tar.gz binaryen-823222ff566b38495327bc28b4726871b0a86b26.tar.bz2 binaryen-823222ff566b38495327bc28b4726871b0a86b26.zip |
[GC] Add struct.new and start to test interesting execution (#3433)
With struct.new read/write support, we can start to do interesting
things! This adds a test of creating a struct and seeing that references
behave like references, that is, if we write to the value X refers to, and
if Y refers to the same thing, when reading from Y's value we see the
change as well.
The test is run through all of -O1, which uncovered a minor issue in
Precompute: We can't try to precompute a reference type, as we can't
replace a reference with a value.
Note btw that the test shows the optimizer properly running
CoalesceLocals on reference types, merging two locals.
Diffstat (limited to 'test')
-rw-r--r-- | test/heap-types.wast | 13 | ||||
-rw-r--r-- | test/heap-types.wast.from-wast | 13 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary | 13 | ||||
-rw-r--r-- | test/heap-types.wast.fromBinary.noDebugInfo | 13 | ||||
-rw-r--r-- | test/passes/O1_fuzz-exec_all-features.txt | 52 | ||||
-rw-r--r-- | test/passes/O1_fuzz-exec_all-features.wast | 37 |
6 files changed, 141 insertions, 0 deletions
diff --git a/test/heap-types.wast b/test/heap-types.wast index 7e44e4fdb..c25c4ac61 100644 --- a/test/heap-types.wast +++ b/test/heap-types.wast @@ -86,6 +86,19 @@ (local.get $x) (i32.const 100) ) + (drop + (struct.new_default_with_rtt $struct.A + (rtt.canon $struct.A) + ) + ) + (drop + (struct.new_with_rtt $struct.A + (rtt.canon $struct.A) + (i32.const 1) + (f32.const 2.345) + (f64.const 3.14159) + ) + ) (unreachable) ) ;; RTT types as parameters diff --git a/test/heap-types.wast.from-wast b/test/heap-types.wast.from-wast index 6f3c20589..3fad50922 100644 --- a/test/heap-types.wast.from-wast +++ b/test/heap-types.wast.from-wast @@ -88,6 +88,19 @@ (local.get $x) (i32.const 100) ) + (drop + (struct.new_default_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + ) + ) + (drop + (struct.new_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + (i32.const 1) + (f32.const 2.3450000286102295) + (f64.const 3.14159) + ) + ) (unreachable) ) (func $rtt-param-with-depth (param $rtt (rtt 1 ${})) diff --git a/test/heap-types.wast.fromBinary b/test/heap-types.wast.fromBinary index 537096fe0..315d30d38 100644 --- a/test/heap-types.wast.fromBinary +++ b/test/heap-types.wast.fromBinary @@ -88,6 +88,19 @@ (local.get $x) (i32.const 100) ) + (drop + (struct.new_default_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + ) + ) + (drop + (struct.new_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + (i32.const 1) + (f32.const 2.3450000286102295) + (f64.const 3.14159) + ) + ) (unreachable) ) (func $rtt-param-with-depth (param $rtt (rtt 1 ${})) diff --git a/test/heap-types.wast.fromBinary.noDebugInfo b/test/heap-types.wast.fromBinary.noDebugInfo index 19e5f701d..9f54a8071 100644 --- a/test/heap-types.wast.fromBinary.noDebugInfo +++ b/test/heap-types.wast.fromBinary.noDebugInfo @@ -88,6 +88,19 @@ (local.get $0) (i32.const 100) ) + (drop + (struct.new_default_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + ) + ) + (drop + (struct.new_with_rtt ${i32_f32_f64} + (rtt.canon ${i32_f32_f64}) + (i32.const 1) + (f32.const 2.3450000286102295) + (f64.const 3.14159) + ) + ) (unreachable) ) (func $1 (param $0 (rtt 1 ${})) diff --git a/test/passes/O1_fuzz-exec_all-features.txt b/test/passes/O1_fuzz-exec_all-features.txt new file mode 100644 index 000000000..522943d69 --- /dev/null +++ b/test/passes/O1_fuzz-exec_all-features.txt @@ -0,0 +1,52 @@ +[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 new file mode 100644 index 000000000..0740e60e7 --- /dev/null +++ b/test/passes/O1_fuzz-exec_all-features.wast @@ -0,0 +1,37 @@ +(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)) + ) + ) +) |