Skip to content

Commit 1a2675f

Browse files
Rollup merge of #82141 - jrvanwhy:issue-82052, r=sanxiyn
32-bit ARM: Emit `lr` instead of `r14` when specified as an `asm!` output register. On 32-bit ARM platforms, the register `r14` has the alias `lr`. When used as an output register in `asm!`, rustc canonicalizes the name to `r14`. LLVM only knows the register by the name `lr`, and rejects it. This changes rustc's LLVM code generation to output `lr` instead. closes #82052 r? ``@nagisa``
2 parents 1ee4a7b + fd21eb1 commit 1a2675f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Diff for: compiler/rustc_codegen_llvm/src/asm.rs

+3
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
487487
} else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) {
488488
// LLVM doesn't recognize x30
489489
"{lr}".to_string()
490+
} else if reg == InlineAsmReg::Arm(ArmInlineAsmReg::r14) {
491+
// LLVM doesn't recognize r14
492+
"{lr}".to_string()
490493
} else {
491494
format!("{{{}}}", reg.name())
492495
}

Diff for: src/test/assembly/asm/arm-types.rs

+9
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ pub unsafe fn sym_static() {
9191
asm!("adr r0, {}", sym extern_static);
9292
}
9393

94+
// Regression test for #82052.
95+
// CHECK-LABEL: issue_82052
96+
// CHECK: push {{.*}}lr
97+
// CHECK: @APP
98+
// CHECK: @NO_APP
99+
pub unsafe fn issue_82052() {
100+
asm!("", out("r14") _);
101+
}
102+
94103
macro_rules! check {
95104
($func:ident $ty:ident $class:ident $mov:literal) => {
96105
#[no_mangle]

0 commit comments

Comments
 (0)