Skip to content

Commit 8bc916e

Browse files
fix: dropkeep not being emited correctly
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent b484f2b commit 8bc916e

3 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎crates/cli/src/load.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn load_module_from_bytes(input: &str, bytes: &[u8]) -> Result<LoadedModule> {
7373

7474
#[cfg(not(feature = "wat"))]
7575
if input != "-" && has_extension(input, "wat") {
76-
bail!("wat support is not enabled in this build")
76+
bail!("wat support is not enabled in this build");
7777
}
7878

7979
#[cfg(feature = "wat")]

‎crates/parser/src/visit.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,8 @@ impl FunctionBuilder<'_> {
10171017

10181018
/// Emits the stack-shaping instruction required by a branch.
10191019
fn emit_dropkeep(&mut self, base: ValueCounts, keep: ValueCounts) {
1020-
if base.is_empty() && keep.is_empty() {
1020+
let target = ValueCounts { c32: base.c32 + keep.c32, c64: base.c64 + keep.c64, c128: base.c128 + keep.c128 };
1021+
if self.lane_counts == target {
10211022
return;
10221023
}
10231024
self.instructions.push(Instruction::DropKeep((base, keep).into()));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(module
2+
;; Reduced from miniz_oxide's Huffman-table builder, which reached a bounds
3+
;; panic during compression. Branches to empty targets skipped DropKeep, so
4+
;; a stale operand remained on the stack and corrupted a later loop.
5+
(func (export "branch-drops-retained") (result i32)
6+
(local $iteration i32)
7+
(local $count i32)
8+
(local $result i32)
9+
block $done
10+
loop $outer
11+
block $scan-done
12+
i32.const 7
13+
i32.const 20
14+
local.get $iteration
15+
select
16+
local.get $iteration
17+
i32.eqz
18+
if
19+
br $scan-done
20+
end
21+
i32.const 2
22+
local.set $count
23+
loop $inner
24+
local.get $count
25+
i32.const 1
26+
i32.sub
27+
local.tee $count
28+
br_if $inner
29+
end
30+
local.set $result
31+
br $done
32+
end
33+
local.get $iteration
34+
i32.const 1
35+
i32.add
36+
local.set $iteration
37+
br $outer
38+
end
39+
end
40+
local.get $result)
41+
)
42+
43+
(assert_return (invoke "branch-drops-retained") (i32.const 7))

0 commit comments

Comments
 (0)