Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add naked_functions_target_feature unstable feature #138570

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
@@ -568,6 +568,8 @@ declare_features! (
(incomplete, mut_ref, "1.79.0", Some(123076)),
/// Allows using `#[naked]` on functions.
(unstable, naked_functions, "1.9.0", Some(90957)),
/// Allows using `#[target_feature(enable = "...")]` on `#[naked]` on functions.
(unstable, naked_functions_target_feature, "1.86.0", Some(138568)),
/// Allows specifying the as-needed link modifier
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
/// Allow negative trait implementations.
16 changes: 15 additions & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
@@ -598,7 +598,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
sym::repr,
// code generation
sym::cold,
sym::target_feature,
// documentation
sym::doc,
];
@@ -624,6 +623,21 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
_ => {}
}

if other_attr.has_name(sym::target_feature) {
if !self.tcx.features().naked_functions_target_feature() {
feature_err(
&self.tcx.sess,
sym::naked_functions_target_feature,
other_attr.span(),
"`#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions",
).emit();

return;
} else {
continue;
}
}

if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span(),
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -1375,6 +1375,7 @@ symbols! {
naked,
naked_asm,
naked_functions,
naked_functions_target_feature,
name,
names,
native_link_modifiers,
21 changes: 21 additions & 0 deletions tests/ui/asm/naked-functions-target-feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ build-pass
//@ needs-asm-support

#![feature(naked_functions, naked_functions_target_feature)]
#![crate_type = "lib"]

use std::arch::{asm, naked_asm};

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
#[naked]
pub unsafe extern "C" fn compatible_target_feature() {
naked_asm!("");
}

#[cfg(target_arch = "aarch64")]
#[target_feature(enable = "neon")]
#[naked]
pub unsafe extern "C" fn compatible_target_feature() {
naked_asm!("");
}
7 changes: 0 additions & 7 deletions tests/ui/asm/naked-functions.rs
Original file line number Diff line number Diff line change
@@ -230,13 +230,6 @@ pub unsafe extern "C" fn compatible_codegen_attributes() {
naked_asm!("", options(raw));
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
#[naked]
pub unsafe extern "C" fn compatible_target_feature() {
naked_asm!("");
}

#[doc = "foo bar baz"]
/// a doc comment
// a normal comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ needs-asm-support
//@ only-x86_64

#![feature(naked_functions)]

use std::arch::naked_asm;

#[naked]
#[target_feature(enable = "avx2")]
//~^ ERROR: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
extern "C" fn naked() {
unsafe { naked_asm!("") }
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: `#[target_feature(/* ... */)]` is currently unstable on `#[naked]` functions
--> $DIR/feature-gate-naked_functions_target_feature.rs:9:1
|
LL | #[target_feature(enable = "avx2")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #138568 <https://github.com/rust-lang/rust/issues/138568> for more information
= help: add `#![feature(naked_functions_target_feature)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
Loading
Oops, something went wrong.