Skip to content

Commit 06e308e

Browse files
committed
Preserve uext and sext flags for parameters on x86_64 and apple aarch64
This is required by the ABI and prevents a miscompilation when calling LLVM compiled functions.
1 parent b995e2f commit 06e308e

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

cranelift/codegen/src/isa/aarch64/abi.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,14 @@ impl ABIMachineSpec for AArch64MachineDeps {
11481148
}
11491149

11501150
fn get_ext_mode(
1151-
_call_conv: isa::CallConv,
1152-
_specified: ir::ArgumentExtension,
1151+
call_conv: isa::CallConv,
1152+
specified: ir::ArgumentExtension,
11531153
) -> ir::ArgumentExtension {
1154-
ir::ArgumentExtension::None
1154+
if call_conv == isa::CallConv::AppleAarch64 {
1155+
specified
1156+
} else {
1157+
ir::ArgumentExtension::None
1158+
}
11551159
}
11561160

11571161
fn compute_frame_layout(

cranelift/codegen/src/isa/x64/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,9 @@ impl ABIMachineSpec for X64ABIMachineSpec {
809809

810810
fn get_ext_mode(
811811
_call_conv: isa::CallConv,
812-
_specified: ir::ArgumentExtension,
812+
specified: ir::ArgumentExtension,
813813
) -> ir::ArgumentExtension {
814-
ir::ArgumentExtension::None
814+
specified
815815
}
816816

817817
fn compute_frame_layout(
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
test compile
2+
target aarch64
3+
4+
; The aapcs64 call conv ignores the uext and sext flags
5+
function u0:0(i8) system_v {
6+
sig0 = (i8 uext) system_v
7+
fn0 = u0:0 sig0
8+
9+
block0(v0: i8):
10+
call fn0(v0)
11+
return
12+
}
13+
14+
; check: stp fp, lr, [sp, #-16]!
15+
; nextln: mov fp, sp
16+
; nextln: block0:
17+
; check-not: uxtb w0, w0
18+
; nextln: load_ext_name x2, User(userextname0)+0
19+
; nextln: blr x2
20+
21+
; The aaple aarch64 call conv respects the uext and sext flags
22+
function u0:0(i8) apple_aarch64 {
23+
sig0 = (i8 uext) apple_aarch64
24+
fn0 = u0:0 sig0
25+
26+
block0(v0: i8):
27+
call fn0(v0)
28+
return
29+
}
30+
31+
; check: stp fp, lr, [sp, #-16]!
32+
; nextln: mov fp, sp
33+
; nextln: block0:
34+
; nextln: uxtb w0, w0
35+
; nextln: load_ext_name x4, User(userextname0)+0
36+
; nextln: blr x4
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
test compile
2+
target x86_64
3+
4+
; The x86_64 system_v call conv respects uext and sext
5+
function u0:0(i8) system_v {
6+
sig0 = (i8 uext) system_v
7+
fn0 = u0:0 sig0
8+
9+
block0(v0: i8):
10+
call fn0(v0)
11+
return
12+
}
13+
14+
; check: pushq %rbp
15+
; nextln: movq %rsp, %rbp
16+
; nextln: block0:
17+
; nextln: movzbq %dil, %rdi
18+
; nextln: load_ext_name userextname0+0, %rdx
19+
; nextln: call *%rdx
20+
21+
; The x86_64 windows_fastcall call conv respects uext and sext
22+
function u0:0(i8) windows_fastcall {
23+
sig0 = (i8 uext) windows_fastcall
24+
fn0 = u0:0 sig0
25+
26+
block0(v0: i8):
27+
call fn0(v0)
28+
return
29+
}
30+
31+
; check: pushq %rbp
32+
; nextln: movq %rsp, %rbp
33+
; nextln: block0:
34+
; nextln: subq %rsp, $$32, %rsp
35+
; nextln: virtual_sp_offset_adjust 32
36+
; nextln: movzbq %cl, %rcx
37+
; nextln: load_ext_name userextname0+0, %r9
38+
; nextln: call *%r9

0 commit comments

Comments
 (0)