Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support clobber_abi in MSP430 inline assembly #131310

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ pub enum InlineAsmClobberAbi {
RiscV,
LoongArch,
S390x,
Msp430,
}

impl InlineAsmClobberAbi {
Expand Down Expand Up @@ -946,6 +947,10 @@ impl InlineAsmClobberAbi {
"C" | "system" => Ok(InlineAsmClobberAbi::S390x),
_ => Err(&["C", "system"]),
},
InlineAsmArch::Msp430 => match name {
"C" | "system" => Ok(InlineAsmClobberAbi::Msp430),
_ => Err(&["C", "system"]),
},
_ => Err(&[]),
}
}
Expand Down Expand Up @@ -1125,6 +1130,11 @@ impl InlineAsmClobberAbi {
a8, a9, a10, a11, a12, a13, a14, a15,
}
},
InlineAsmClobberAbi::Msp430 => clobbered_regs! {
Msp430 Msp430InlineAsmReg {
r11, r12, r13, r14, r15,
}
},
}
}
}
36 changes: 36 additions & 0 deletions tests/codegen/asm-msp430-clobbers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@ assembly-output: emit-asm
//@ compile-flags: --target msp430-none-elf
//@ needs-llvm-components: msp430

#![crate_type = "rlib"]
#![feature(no_core, rustc_attrs, lang_items, asm_experimental_arch)]
#![no_core]

#[lang = "sized"]
trait Sized {}

#[rustc_builtin_macro]
macro_rules! asm {
() => {};
}

// CHECK-LABEL: @sr_clobber
// CHECK: call void asm sideeffect "", "~{sr}"()
#[no_mangle]
pub unsafe fn sr_clobber() {
asm!("", options(nostack, nomem));
}

// CHECK-LABEL: @no_clobber
// CHECK: call void asm sideeffect "", ""()
#[no_mangle]
pub unsafe fn no_clobber() {
asm!("", options(nostack, nomem, preserves_flags));
}

// CHECK-LABEL: @clobber_abi
// CHECK: asm sideeffect "", "={r11},={r12},={r13},={r14},={r15}"()
#[no_mangle]
pub unsafe fn clobber_abi() {
asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags));
}
Loading