Skip to content

Commit

Permalink
Rollup merge of #82141 - jrvanwhy:issue-82052, r=sanxiyn
Browse files Browse the repository at this point in the history
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``
  • Loading branch information
jonas-schievink committed Feb 15, 2021
2 parents 1ee4a7b + fd21eb1 commit 1a2675f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>)
} else if reg == InlineAsmReg::AArch64(AArch64InlineAsmReg::x30) {
// LLVM doesn't recognize x30
"{lr}".to_string()
} else if reg == InlineAsmReg::Arm(ArmInlineAsmReg::r14) {
// LLVM doesn't recognize r14
"{lr}".to_string()
} else {
format!("{{{}}}", reg.name())
}
Expand Down
9 changes: 9 additions & 0 deletions src/test/assembly/asm/arm-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ pub unsafe fn sym_static() {
asm!("adr r0, {}", sym extern_static);
}

// Regression test for #82052.
// CHECK-LABEL: issue_82052
// CHECK: push {{.*}}lr
// CHECK: @APP
// CHECK: @NO_APP
pub unsafe fn issue_82052() {
asm!("", out("r14") _);
}

macro_rules! check {
($func:ident $ty:ident $class:ident $mov:literal) => {
#[no_mangle]
Expand Down

0 comments on commit 1a2675f

Please sign in to comment.