diff options
author | Alon Zakai <azakai@google.com> | 2023-02-14 11:20:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 11:20:25 -0800 |
commit | 3a315fb8248be7a2a7b7e27ebfde634d05668bf3 (patch) | |
tree | 5628b42f655362d9f07e025fe0b52a0528cd3e9d | |
parent | 0fbfedabb9339995a7a8040414aafcc86004b973 (diff) | |
download | binaryen-3a315fb8248be7a2a7b7e27ebfde634d05668bf3.tar.gz binaryen-3a315fb8248be7a2a7b7e27ebfde634d05668bf3.tar.bz2 binaryen-3a315fb8248be7a2a7b7e27ebfde634d05668bf3.zip |
[Wasm GC] Fix array.new order of operand execution (#5487)
-rw-r--r-- | src/wasm-interpreter.h | 11 | ||||
-rw-r--r-- | test/lit/exec/array.wast | 20 |
2 files changed, 27 insertions, 4 deletions
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 43b001f35..6d25e4398 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -1595,6 +1595,13 @@ public: Flow visitArrayNew(ArrayNew* curr) { NOTE_ENTER("ArrayNew"); + Flow init; + if (!curr->isWithDefault()) { + init = self()->visit(curr->init); + if (init.breaking()) { + return init; + } + } auto size = self()->visit(curr->size); if (size.breaking()) { return size; @@ -1618,10 +1625,6 @@ public: data[i] = Literal::makeZero(element.type); } } else { - auto init = self()->visit(curr->init); - if (init.breaking()) { - return init; - } auto field = curr->type.getHeapType().getArray().element; auto value = truncateForPacking(init.getSingleValue(), field); for (Index i = 0; i < num; i++) { diff --git a/test/lit/exec/array.wast b/test/lit/exec/array.wast new file mode 100644 index 000000000..7e74c7b7d --- /dev/null +++ b/test/lit/exec/array.wast @@ -0,0 +1,20 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited. + +;; RUN: wasm-opt %s -all --fuzz-exec -q -o /dev/null 2>&1 | filecheck %s + +(module + (type $array (array (mut i8))) + + ;; CHECK: [fuzz-exec] calling func + ;; CHECK-NEXT: [fuzz-exec] note result: func => 1 + (func "func" (result i32) + ;; Verifies the order of execution is correct - we should return 1, not 2. + (array.new $array + (return (i32.const 1)) + (return (i32.const 2)) + ) + ) +) +;; CHECK: [fuzz-exec] calling func +;; CHECK-NEXT: [fuzz-exec] note result: func => 1 +;; CHECK-NEXT: [fuzz-exec] comparing func |