add repr to the allowlist for naked functions, and test that it works

This commit is contained in:
jdonszelmann 2024-08-22 19:48:39 +02:00
parent 739b1fdb15
commit c3000ad3ba
No known key found for this signature in database
GPG Key ID: E0C1EA36407B2FF2
2 changed files with 21 additions and 0 deletions

View File

@ -516,6 +516,7 @@ fn check_naked(
sym::no_mangle,
sym::naked,
sym::instruction_set,
sym::repr,
// code generation
sym::cold,
sym::target_feature,

View File

@ -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));
}