Skip to content

Commit

Permalink
add repr to the allowlist for naked functions, and test that it works
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Aug 27, 2024
1 parent 739b1fd commit c3000ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
sym::no_mangle,
sym::naked,
sym::instruction_set,
sym::repr,
// code generation
sym::cold,
sym::target_feature,
Expand Down
20 changes: 20 additions & 0 deletions tests/codegen/naked-fn/aligned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0
//@ needs-asm-support
//@ ignore-arm no "ret" mnemonic

#![crate_type = "lib"]
#![feature(naked_functions, fn_align)]
use std::arch::asm;

// CHECK: Function Attrs: naked
// CHECK-NEXT: define{{.*}}void @naked_empty()
// CHECK: align 16
#[repr(align(16))]
#[no_mangle]
#[naked]
pub unsafe extern "C" fn naked_empty() {
// CHECK-NEXT: start:
// CHECK-NEXT: call void asm
// CHECK-NEXT: unreachable
asm!("ret", options(noreturn));
}

0 comments on commit c3000ad

Please sign in to comment.