Skip to content

Commit 3a315fb

Browse files
authored
[Wasm GC] Fix array.new order of operand execution (#5487)
1 parent 0fbfeda commit 3a315fb

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/wasm-interpreter.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,13 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
15951595

15961596
Flow visitArrayNew(ArrayNew* curr) {
15971597
NOTE_ENTER("ArrayNew");
1598+
Flow init;
1599+
if (!curr->isWithDefault()) {
1600+
init = self()->visit(curr->init);
1601+
if (init.breaking()) {
1602+
return init;
1603+
}
1604+
}
15981605
auto size = self()->visit(curr->size);
15991606
if (size.breaking()) {
16001607
return size;
@@ -1618,10 +1625,6 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
16181625
data[i] = Literal::makeZero(element.type);
16191626
}
16201627
} else {
1621-
auto init = self()->visit(curr->init);
1622-
if (init.breaking()) {
1623-
return init;
1624-
}
16251628
auto field = curr->type.getHeapType().getArray().element;
16261629
auto value = truncateForPacking(init.getSingleValue(), field);
16271630
for (Index i = 0; i < num; i++) {

test/lit/exec/array.wast

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --output=fuzz-exec and should not be edited.
2+
3+
;; RUN: wasm-opt %s -all --fuzz-exec -q -o /dev/null 2>&1 | filecheck %s
4+
5+
(module
6+
(type $array (array (mut i8)))
7+
8+
;; CHECK: [fuzz-exec] calling func
9+
;; CHECK-NEXT: [fuzz-exec] note result: func => 1
10+
(func "func" (result i32)
11+
;; Verifies the order of execution is correct - we should return 1, not 2.
12+
(array.new $array
13+
(return (i32.const 1))
14+
(return (i32.const 2))
15+
)
16+
)
17+
)
18+
;; CHECK: [fuzz-exec] calling func
19+
;; CHECK-NEXT: [fuzz-exec] note result: func => 1
20+
;; CHECK-NEXT: [fuzz-exec] comparing func

0 commit comments

Comments
 (0)