Skip to content

Commit 3743618

Browse files
committed
Support clobber_abi in MSP430 inline assembly
1 parent 3002af6 commit 3743618

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

compiler/rustc_target/src/asm/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ pub enum InlineAsmClobberAbi {
893893
RiscV,
894894
LoongArch,
895895
S390x,
896+
Msp430,
896897
}
897898

898899
impl InlineAsmClobberAbi {
@@ -946,6 +947,10 @@ impl InlineAsmClobberAbi {
946947
"C" | "system" => Ok(InlineAsmClobberAbi::S390x),
947948
_ => Err(&["C", "system"]),
948949
},
950+
InlineAsmArch::Msp430 => match name {
951+
"C" | "system" => Ok(InlineAsmClobberAbi::Msp430),
952+
_ => Err(&["C", "system"]),
953+
},
949954
_ => Err(&[]),
950955
}
951956
}
@@ -1125,6 +1130,11 @@ impl InlineAsmClobberAbi {
11251130
a8, a9, a10, a11, a12, a13, a14, a15,
11261131
}
11271132
},
1133+
InlineAsmClobberAbi::Msp430 => clobbered_regs! {
1134+
Msp430 Msp430InlineAsmReg {
1135+
r11, r12, r13, r14, r15,
1136+
}
1137+
},
11281138
}
11291139
}
11301140
}

tests/codegen/asm-msp430-clobbers.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ assembly-output: emit-asm
2+
//@ compile-flags: --target msp430-none-elf
3+
//@ needs-llvm-components: msp430
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: @sr_clobber
18+
// CHECK: call void asm sideeffect "", "~{sr}"()
19+
#[no_mangle]
20+
pub unsafe fn sr_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 "", "={r11},={r12},={r13},={r14},={r15}"()
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)