Skip to content

Commit 62fa364

Browse files
authored
Winch: Free dst register if computing heap address fails (#10561)
* Winch: Free dst register if computing heap address fails * Add Wast test
1 parent 073aeda commit 62fa364

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
;;! target = "x86_64"
2+
;;! test = "winch"
3+
;;! flags = [ "-Ccranelift-has-avx" ]
4+
5+
(module
6+
(memory 0 0)
7+
(func (result f32)
8+
i32.const 0
9+
if
10+
unreachable
11+
end
12+
i32.const 0
13+
v128.const i64x2 0 0
14+
v128.load64_lane align=1 0
15+
drop
16+
f32.const 0
17+
)
18+
)
19+
;; wasm[0]::function[0]:
20+
;; pushq %rbp
21+
;; movq %rsp, %rbp
22+
;; movq 8(%rdi), %r11
23+
;; movq 0x10(%r11), %r11
24+
;; addq $0x10, %r11
25+
;; cmpq %rsp, %r11
26+
;; ja 0x5e
27+
;; 1c: movq %rdi, %r14
28+
;; subq $0x10, %rsp
29+
;; movq %rdi, 8(%rsp)
30+
;; movq %rsi, (%rsp)
31+
;; movl $0, %eax
32+
;; testl %eax, %eax
33+
;; je 0x3b
34+
;; 39: ud2
35+
;; movdqu 0x1d(%rip), %xmm0
36+
;; movl $0, %eax
37+
;; movq 8(%r14), %rcx
38+
;; movq (%rcx), %r11
39+
;; addq $1, %r11
40+
;; movq %r11, (%rcx)
41+
;; ud2
42+
;; addq $0x10, %rsp
43+
;; popq %rbp
44+
;; retq
45+
;; 5e: ud2
46+
;; 60: addb %al, (%rax)
47+
;; 62: addb %al, (%rax)
48+
;; 64: addb %al, (%rax)
49+
;; 66: addb %al, (%rax)
50+
;; 68: addb %al, (%rax)
51+
;; 6a: addb %al, (%rax)
52+
;; 6c: addb %al, (%rax)
53+
;; 6e: addb %al, (%rax)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;;! simd = true
2+
3+
(module
4+
(memory 0 0)
5+
(func (export "test") (result f32)
6+
i32.const 0
7+
if
8+
unreachable
9+
end
10+
i32.const 0
11+
v128.const i64x2 0 0
12+
v128.load64_lane align=1 0
13+
drop
14+
f32.const 0
15+
)
16+
)
17+
18+
(assert_trap (invoke "test") "out of bounds memory access")

winch/codegen/src/codegen/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,12 +908,19 @@ where
908908
Ok(())
909909
};
910910

911+
// Ensure that the destination register is not allocated if
912+
// `emit_compute_heap_address` does not return an address.
911913
match kind {
912914
LoadKind::VectorLane(_) => {
915+
// Destination vector register is at the top of the stack and
916+
// `emit_compute_heap_address` expects an integer register
917+
// containing the address to load to be at the top of the stack.
913918
let dst = self.context.pop_to_reg(self.masm, None)?;
914919
let addr = self.emit_compute_heap_address(&arg, kind.derive_operand_size())?;
915920
if let Some(addr) = addr {
916921
emit_load(self, dst.reg, addr, kind)?;
922+
} else {
923+
self.context.free_reg(dst);
917924
}
918925
}
919926
_ => {

0 commit comments

Comments
 (0)