Skip to content

Commit

Permalink
check that assembler mode restored
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Sep 27, 2024
1 parent 3b2d1d3 commit 6311843
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_middle::{bug, ty};
use rustc_span::sym;

use crate::common;
use crate::traits::{AsmMethods, BuilderMethods, GlobalAsmOperandRef, MiscMethods};
use crate::traits::{AsmCodegenMethods, BuilderMethods, GlobalAsmOperandRef, MiscCodegenMethods};

pub(crate) fn codegen_naked_asm<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx: &'a Bx::CodegenCx,
Expand Down Expand Up @@ -131,15 +131,17 @@ fn prefix_and_suffix<'tcx>(
let link_section = attrs.link_section.map(|symbol| symbol.as_str().to_string());
let align = attrs.alignment.map(|a| a.bytes()).unwrap_or(4);

// See https://sourceware.org/binutils/docs/as/ARM-Directives.html for info on these directives.
// In particular, `.arm` can also be written `.code 32` and `.thumb` as `.code 16`.
let (arch_prefix, arch_suffix) = if is_arm {
(
match attrs.instruction_set {
None => match is_thumb {
true => ".thumb\n.thumb_func",
false => ".arm",
},
Some(InstructionSetAttr::ArmA32) => ".arm",
Some(InstructionSetAttr::ArmT32) => ".thumb\n.thumb_func",
Some(InstructionSetAttr::ArmA32) => ".arm",
},
match is_thumb {
true => ".thumb",
Expand Down
27 changes: 21 additions & 6 deletions tests/codegen/naked-fn/instruction-set.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//@ compile-flags: --target armv5te-none-eabi
//@ needs-llvm-components: arm
//@ revisions: arm-mode thumb-mode
//@ [arm-mode] compile-flags: --target armv5te-none-eabi
//@ [thumb-mode] compile-flags: --target thumbv5te-none-eabi
//@ [arm-mode] needs-llvm-components: arm
//@ [thumb-mode] needs-llvm-components: arm

#![crate_type = "lib"]
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
Expand All @@ -15,29 +18,41 @@ trait Sized {}
#[lang = "copy"]
trait Copy {}

// CHECK-LABEL: test_unspecified:
// CHECK: .arm
// CHECK-LABEL: test_unspecified:
// CHECK: bx lr
// CHECK: .popsection
// arm-mode: .arm
// thumb-mode: .thumb
#[no_mangle]
#[naked]
unsafe extern "C" fn test_unspecified() {
asm!("bx lr", options(noreturn));
}

// CHECK-LABEL: test_thumb:
// CHECK: .thumb
// CHECK: .thumb_func
// CHECK-LABEL: test_thumb:
// CHECK: bx lr
// CHECK: .popsection
// arm-mode: .arm
// thumb-mode: .thumb
#[no_mangle]
#[naked]
#[instruction_set(arm::t32)]
unsafe extern "C" fn test_thumb() {
asm!("bx lr", options(noreturn));
}

// CHECK-LABEL: test_arm:
// CHECK: .arm
// CHECK-LABEL: test_arm:
// CHECK: bx lr
// CHECK: .popsection
// arm-mode: .arm
// thumb-mode: .thumb
#[no_mangle]
#[naked]
#[instruction_set(arm::t32)]
#[instruction_set(arm::a32)]
unsafe extern "C" fn test_arm() {
asm!("bx lr", options(noreturn));
}

0 comments on commit 6311843

Please sign in to comment.