Skip to content

Commit 08eb832

Browse files
committed
Fix clobber_abi in Arm64EC inline assembly
1 parent 96d9d8a commit 08eb832

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

compiler/rustc_target/src/asm/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ pub enum InlineAsmClobberAbi {
890890
Arm,
891891
AArch64,
892892
AArch64NoX18,
893+
Arm64EC,
893894
RiscV,
894895
LoongArch,
895896
S390x,
@@ -931,7 +932,7 @@ impl InlineAsmClobberAbi {
931932
_ => Err(&["C", "system", "efiapi"]),
932933
},
933934
InlineAsmArch::Arm64EC => match name {
934-
"C" | "system" => Ok(InlineAsmClobberAbi::AArch64NoX18),
935+
"C" | "system" => Ok(InlineAsmClobberAbi::Arm64EC),
935936
_ => Err(&["C", "system"]),
936937
},
937938
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => match name {
@@ -1028,7 +1029,6 @@ impl InlineAsmClobberAbi {
10281029
p0, p1, p2, p3, p4, p5, p6, p7,
10291030
p8, p9, p10, p11, p12, p13, p14, p15,
10301031
ffr,
1031-
10321032
}
10331033
},
10341034
InlineAsmClobberAbi::AArch64NoX18 => clobbered_regs! {
@@ -1047,7 +1047,24 @@ impl InlineAsmClobberAbi {
10471047
p0, p1, p2, p3, p4, p5, p6, p7,
10481048
p8, p9, p10, p11, p12, p13, p14, p15,
10491049
ffr,
1050+
}
1051+
},
1052+
InlineAsmClobberAbi::Arm64EC => clobbered_regs! {
1053+
AArch64 AArch64InlineAsmReg {
1054+
// x13 and x14 cannot be used in Arm64EC.
1055+
x0, x1, x2, x3, x4, x5, x6, x7,
1056+
x8, x9, x10, x11, x12, x15,
1057+
x16, x17, x30,
10501058

1059+
// Technically the low 64 bits of v8-v15 are preserved, but
1060+
// we have no way of expressing this using clobbers.
1061+
v0, v1, v2, v3, v4, v5, v6, v7,
1062+
v8, v9, v10, v11, v12, v13, v14, v15,
1063+
// v16-v31 cannot be used in Arm64EC.
1064+
1065+
p0, p1, p2, p3, p4, p5, p6, p7,
1066+
p8, p9, p10, p11, p12, p13, p14, p15,
1067+
ffr,
10511068
}
10521069
},
10531070
InlineAsmClobberAbi::Arm => clobbered_regs! {

tests/codegen/asm-arm64ec-clobbers.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target arm64ec-pc-windows-msvc
3+
//@ needs-llvm-components: aarch64
4+
5+
#![crate_type = "rlib"]
6+
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
7+
#![no_core]
8+
9+
#[lang = "sized"]
10+
trait Sized {}
11+
12+
#[rustc_builtin_macro]
13+
macro_rules! asm {
14+
() => {};
15+
}
16+
17+
// CHECK-LABEL: @cc_clobber
18+
// CHECK: call void asm sideeffect "", "~{cc}"()
19+
#[no_mangle]
20+
pub unsafe fn cc_clobber() {
21+
asm!("", options(nostack, nomem));
22+
}
23+
24+
// CHECK-LABEL: @no_clobber
25+
// CHECK: call void asm sideeffect "", ""()
26+
#[no_mangle]
27+
pub unsafe fn no_clobber() {
28+
asm!("", options(nostack, nomem, preserves_flags));
29+
}
30+
31+
// CHECK-LABEL: @clobber_abi
32+
// CHECK: asm sideeffect "", "={w0},={w1},={w2},={w3},={w4},={w5},={w6},={w7},={w8},={w9},={w10},={w11},={w12},={w15},={w16},={w17},={w30},={q0},={q1},={q2},={q3},={q4},={q5},={q6},={q7},={q8},={q9},={q10},={q11},={q12},={q13},={q14},={q15},~{p0},~{p1},~{p2},~{p3},~{p4},~{p5},~{p6},~{p7},~{p8},~{p9},~{p10},~{p11},~{p12},~{p13},~{p14},~{p15},~{ffr}"()
33+
#[no_mangle]
34+
pub unsafe fn clobber_abi() {
35+
asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags));
36+
}

0 commit comments

Comments
 (0)