diff options
author | Alon Zakai <azakai@google.com> | 2021-09-14 12:47:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-14 19:47:28 +0000 |
commit | e61393d27b031435d11160f3f91e1e8b8583c0c0 (patch) | |
tree | 93473a87764b753f1bb2c401a5015c8829f6c5cd | |
parent | 9e2f13a2d14284cbc3e6dd4d5f891fa5df895436 (diff) | |
download | binaryen-e61393d27b031435d11160f3f91e1e8b8583c0c0.tar.gz binaryen-e61393d27b031435d11160f3f91e1e8b8583c0c0.tar.bz2 binaryen-e61393d27b031435d11160f3f91e1e8b8583c0c0.zip |
[Wasm GC] Fix lack of packing in array.init (#4153)
-rw-r--r-- | src/wasm-interpreter.h | 3 | ||||
-rw-r--r-- | test/passes/Oz_fuzz-exec_all-features.txt | 16 | ||||
-rw-r--r-- | test/passes/Oz_fuzz-exec_all-features.wast | 13 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 9fc11de76..8dd7859ac 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1712,13 +1712,14 @@ public: if (num >= ArrayLimit) { hostLimit("allocation failure"); } + auto field = curr->type.getHeapType().getArray().element; Literals data(num); for (Index i = 0; i < num; i++) { auto value = this->visit(curr->values[i]); if (value.breaking()) { return value; } - data[i] = value.getSingleValue(); + data[i] = truncateForPacking(value.getSingleValue(), field); } return Flow(Literal(std::make_shared<GCData>(rtt.getSingleValue(), data), curr->type)); diff --git a/test/passes/Oz_fuzz-exec_all-features.txt b/test/passes/Oz_fuzz-exec_all-features.txt index 4ac373f75..1360d6b42 100644 --- a/test/passes/Oz_fuzz-exec_all-features.txt +++ b/test/passes/Oz_fuzz-exec_all-features.txt @@ -65,6 +65,8 @@ [LoggingExternalInterface logging 2] [LoggingExternalInterface logging 42] [LoggingExternalInterface logging 50] +[fuzz-exec] calling array.init-packed +[LoggingExternalInterface logging 8] (module (type $extendedstruct (struct (field (mut i32)) (field f64))) (type $struct (struct (field (mut i32)))) @@ -95,6 +97,7 @@ (export "array-copy" (func $20)) (export "rtt_Fresh" (func $21)) (export "array.init" (func $22)) + (export "array.init-packed" (func $23)) (func $0 (; has Stack IR ;) (local $0 i32) (call $log @@ -487,6 +490,17 @@ ) ) ) + (func $23 (; has Stack IR ;) + (call $log + (array.get_u $bytes + (array.init $bytes + (i32.const -11512) + (rtt.canon $bytes) + ) + (i32.const 0) + ) + ) + ) ) [fuzz-exec] calling structs [LoggingExternalInterface logging 0] @@ -554,6 +568,8 @@ [LoggingExternalInterface logging 2] [LoggingExternalInterface logging 42] [LoggingExternalInterface logging 50] +[fuzz-exec] calling array.init-packed +[LoggingExternalInterface logging 8] ignoring comparison of ExecutionResults! [fuzz-exec] calling foo [host limit allocation failure] diff --git a/test/passes/Oz_fuzz-exec_all-features.wast b/test/passes/Oz_fuzz-exec_all-features.wast index a41e2bf70..54d93c9d0 100644 --- a/test/passes/Oz_fuzz-exec_all-features.wast +++ b/test/passes/Oz_fuzz-exec_all-features.wast @@ -497,6 +497,19 @@ (array.get_u $bytes (local.get $x) (i32.const 1)) ) ) + (func "array.init-packed" + (local $x (ref null $bytes)) + (local.set $x + (array.init $bytes + (i32.const -11512) + (rtt.canon $bytes) + ) + ) + ;; The value should be be -11512 & 255 => 8 + (call $log + (array.get_u $bytes (local.get $x) (i32.const 0)) + ) + ) ) (module (type $[mut:i8] (array (mut i8))) |