Skip to content

Commit f89d910

Browse files
authored
winch: Fix a host panic when executing table.fill (#13010)
This commit fixes a possible panic when a Winch-compiled module executes the `table.fill` instruction. Refactoring in #11254 updated Cranelift but forgot to update Winch meaning that Winch's indices were still using the module-level indices instead of the `DefinedTableIndex` space. This adds some tests and updates Winch's translation to use preexisting helpers.
1 parent 7a10525 commit f89d910

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

tests/misc_testsuite/winch/table_fill.wast

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,39 @@
6565
(invoke "fill" (i32.const 8) (i32.const 0) (i32.const 3))
6666
"out of bounds table access"
6767
)
68+
69+
(module $t
70+
(table (export "t") 1 funcref)
71+
)
72+
73+
(module
74+
(import "t" "t" (table $t1 1 funcref))
75+
(table $t2 2 funcref)
76+
77+
(func (export "fill1") (param i32 funcref i32)
78+
local.get 0
79+
local.get 1
80+
local.get 2
81+
table.fill $t1)
82+
83+
(func (export "fill2") (param i32 funcref i32)
84+
local.get 0
85+
local.get 1
86+
local.get 2
87+
table.fill $t2)
88+
)
89+
90+
(assert_return (invoke "fill1" (i32.const 0) (ref.null func) (i32.const 0)))
91+
(assert_return (invoke "fill1" (i32.const 0) (ref.null func) (i32.const 1)))
92+
(assert_return (invoke "fill1" (i32.const 1) (ref.null func) (i32.const 0)))
93+
(assert_trap (invoke "fill1" (i32.const 2) (ref.null func) (i32.const 0))
94+
"out of bounds table access")
95+
96+
(assert_return (invoke "fill2" (i32.const 0) (ref.null func) (i32.const 0)))
97+
(assert_return (invoke "fill2" (i32.const 0) (ref.null func) (i32.const 1)))
98+
(assert_return (invoke "fill2" (i32.const 0) (ref.null func) (i32.const 2)))
99+
(assert_return (invoke "fill2" (i32.const 1) (ref.null func) (i32.const 0)))
100+
(assert_return (invoke "fill2" (i32.const 1) (ref.null func) (i32.const 1)))
101+
(assert_return (invoke "fill2" (i32.const 2) (ref.null func) (i32.const 0)))
102+
(assert_trap (invoke "fill2" (i32.const 3) (ref.null func) (i32.const 0))
103+
"out of bounds table access")

winch/codegen/src/visitor.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,13 +1805,9 @@ where
18051805

18061806
let at = self.context.stack.ensure_index_at(3)?;
18071807

1808-
self.context.stack.insert_many(at, &[table.try_into()?]);
1809-
FnCall::emit::<M>(
1810-
&mut self.env,
1811-
self.masm,
1812-
&mut self.context,
1813-
Callee::Builtin(builtin.clone()),
1814-
)?;
1808+
let callee = self.prepare_builtin_defined_table_arg(table_index, at, builtin)?;
1809+
FnCall::emit::<M>(&mut self.env, self.masm, &mut self.context, callee)?;
1810+
18151811
self.context.pop_and_free(self.masm)
18161812
}
18171813

0 commit comments

Comments
 (0)