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

Stabilize naked_functions #93587

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0787.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ An unsupported naked function definition.
Erroneous code example:

```compile_fail,E0787
#![feature(naked_functions)]

#[naked]
pub extern "C" fn f() -> u32 {
42
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ declare_features! (
/// Allows patterns with concurrent by-move and by-ref bindings.
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
(accepted, move_ref_pattern, "1.49.0", Some(68354), None),
/// Allows using `#[naked]` on functions.
(accepted, naked_functions, "1.60.0", Some(90957), None),
/// Allows using `#![no_std]`.
(accepted, no_std, "1.6.0", None, None),
/// Allows defining identifiers beyond ASCII.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,6 @@ declare_features! (
(active, more_qualified_paths, "1.54.0", Some(86935), None),
/// Allows the `#[must_not_suspend]` attribute.
(active, must_not_suspend, "1.57.0", Some(83310), None),
/// Allows using `#[naked]` on functions.
(active, naked_functions, "1.9.0", Some(32408), None),
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
(active, native_link_modifiers, "1.53.0", Some(81490), None),
/// Allows specifying the as-needed link modifier
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Code generation:
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
ungated!(cold, Normal, template!(Word), WarnFollowing),
ungated!(naked, Normal, template!(Word), WarnFollowing),
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
Expand All @@ -379,7 +380,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================

// Linking:
gated!(naked, Normal, template!(Word), WarnFollowing, naked_functions, experimental!(naked)),
gated!(
link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
experimental!(link_ordinal)
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2745,8 +2745,6 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(naked_functions)]
///
/// use std::arch::asm;
///
/// #[naked]
Expand Down
2 changes: 0 additions & 2 deletions src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
## Example

```text
#![feature(naked_functions)]

use std::arch::asm;
use std::mem;

Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// only-x86_64

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

use std::arch::asm;

// CHECK: Function Attrs: naked
Expand Down
2 changes: 1 addition & 1 deletion src/test/codegen/naked-noinline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// compile-flags: -O -Zmir-opt-level=3
// needs-asm-support
// ignore-wasm32

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

use std::arch::asm;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/naked-functions-ffi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// check-pass
// needs-asm-support
#![feature(naked_functions)]

#![crate_type = "lib"]

use std::arch::asm;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/naked-functions-unused.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// revisions: x86_64 aarch64
//[x86_64] only-x86_64
//[aarch64] only-aarch64

#![deny(unused)]
#![feature(naked_functions)]
#![crate_type = "lib"]

pub trait Trait {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/naked-functions-unused.x86_64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | pub extern "C" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
|
note: the lint level is defined here
--> $DIR/naked-functions-unused.rs:4:9
--> $DIR/naked-functions-unused.rs:5:9
|
LL | #![deny(unused)]
| ^^^^^^
Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/asm/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// ignore-spirv
// ignore-wasm32

#![feature(naked_functions)]
#![feature(or_patterns)]
#![feature(asm_const, asm_sym, asm_unwind)]
#![crate_type = "lib"]
Expand Down Expand Up @@ -127,7 +126,7 @@ pub unsafe fn default_abi() {
}

#[naked]
pub unsafe fn rust_abi() {
pub unsafe extern "Rust" fn rust_abi() {
//~^ WARN Rust ABI is unsupported in naked functions
asm!("", options(noreturn));
}
Expand Down
68 changes: 34 additions & 34 deletions src/test/ui/asm/naked-functions.stderr
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
error: asm with the `pure` option must have at least one output
--> $DIR/naked-functions.rs:111:14
--> $DIR/naked-functions.rs:110:14
|
LL | asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^

error: patterns not allowed in naked function parameters
--> $DIR/naked-functions.rs:21:5
--> $DIR/naked-functions.rs:20:5
|
LL | mut a: u32,
| ^^^^^

error: patterns not allowed in naked function parameters
--> $DIR/naked-functions.rs:23:5
--> $DIR/naked-functions.rs:22:5
|
LL | &b: &i32,
| ^^

error: patterns not allowed in naked function parameters
--> $DIR/naked-functions.rs:25:6
--> $DIR/naked-functions.rs:24:6
|
LL | (None | Some(_)): Option<std::ptr::NonNull<u8>>,
| ^^^^^^^^^^^^^^

error: patterns not allowed in naked function parameters
--> $DIR/naked-functions.rs:27:5
--> $DIR/naked-functions.rs:26:5
|
LL | P { x, y }: P,
| ^^^^^^^^^^

error: referencing function parameters is not allowed in naked functions
--> $DIR/naked-functions.rs:36:5
--> $DIR/naked-functions.rs:35:5
|
LL | a + 1
| ^
|
= help: follow the calling convention in asm block to use parameters

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:34:1
--> $DIR/naked-functions.rs:33:1
|
LL | / pub unsafe extern "C" fn inc(a: u32) -> u32 {
LL | |
Expand All @@ -48,21 +48,21 @@ LL | | }
| |_^

error: referencing function parameters is not allowed in naked functions
--> $DIR/naked-functions.rs:42:31
--> $DIR/naked-functions.rs:41:31
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
| ^
|
= help: follow the calling convention in asm block to use parameters

error[E0787]: only `const` and `sym` operands are supported in naked functions
--> $DIR/naked-functions.rs:42:23
--> $DIR/naked-functions.rs:41:23
|
LL | asm!("/* {0} */", in(reg) a, options(noreturn));
| ^^^^^^^^^

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:48:1
--> $DIR/naked-functions.rs:47:1
|
LL | / pub unsafe extern "C" fn inc_closure(a: u32) -> u32 {
LL | |
Expand All @@ -72,7 +72,7 @@ LL | | }
| |_^

error[E0787]: only `const` and `sym` operands are supported in naked functions
--> $DIR/naked-functions.rs:65:10
--> $DIR/naked-functions.rs:64:10
|
LL | in(reg) a,
| ^^^^^^^^^
Expand All @@ -87,7 +87,7 @@ LL | out(reg) e,
| ^^^^^^^^^^

error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:63:5
--> $DIR/naked-functions.rs:62:5
|
LL | / asm!("/* {0} {1} {2} {3} {4} {5} {6} */",
LL | |
Expand All @@ -99,7 +99,7 @@ LL | | );
| |_____^

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:54:1
--> $DIR/naked-functions.rs:53:1
|
LL | / pub unsafe extern "C" fn unsupported_operands() {
LL | |
Expand All @@ -119,33 +119,33 @@ LL | | }
| |_^

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:77:1
--> $DIR/naked-functions.rs:76:1
|
LL | / pub extern "C" fn missing_assembly() {
LL | |
LL | | }
| |_^

error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:84:5
--> $DIR/naked-functions.rs:83:5
|
LL | asm!("");
| ^^^^^^^^

error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:86:5
--> $DIR/naked-functions.rs:85:5
|
LL | asm!("");
| ^^^^^^^^

error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:88:5
--> $DIR/naked-functions.rs:87:5
|
LL | asm!("");
| ^^^^^^^^

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:82:1
--> $DIR/naked-functions.rs:81:1
|
LL | / pub extern "C" fn too_many_asm_blocks() {
LL | |
Expand All @@ -163,15 +163,15 @@ LL | | }
| |_^

error: referencing function parameters is not allowed in naked functions
--> $DIR/naked-functions.rs:97:11
--> $DIR/naked-functions.rs:96:11
|
LL | *&y
| ^
|
= help: follow the calling convention in asm block to use parameters

error[E0787]: naked functions must contain a single asm block
--> $DIR/naked-functions.rs:95:5
--> $DIR/naked-functions.rs:94:5
|
LL | / pub extern "C" fn inner(y: usize) -> usize {
LL | |
Expand All @@ -182,75 +182,75 @@ LL | | }
| |_____^

error[E0787]: asm options unsupported in naked functions: `nomem`, `preserves_flags`
--> $DIR/naked-functions.rs:105:5
--> $DIR/naked-functions.rs:104:5
|
LL | asm!("", options(nomem, preserves_flags, noreturn));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0787]: asm options unsupported in naked functions: `nostack`, `pure`, `readonly`
--> $DIR/naked-functions.rs:111:5
--> $DIR/naked-functions.rs:110:5
|
LL | asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0787]: asm in naked functions must use `noreturn` option
--> $DIR/naked-functions.rs:111:5
--> $DIR/naked-functions.rs:110:5
|
LL | asm!("", options(readonly, nostack), options(pure));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0787]: asm options unsupported in naked functions: `may_unwind`
--> $DIR/naked-functions.rs:119:5
--> $DIR/naked-functions.rs:118:5
|
LL | asm!("", options(noreturn, may_unwind));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: Rust ABI is unsupported in naked functions
--> $DIR/naked-functions.rs:124:15
--> $DIR/naked-functions.rs:123:15
|
LL | pub unsafe fn default_abi() {
| ^^^^^^^^^^^
|
= note: `#[warn(undefined_naked_function_abi)]` on by default

warning: Rust ABI is unsupported in naked functions
--> $DIR/naked-functions.rs:130:15
--> $DIR/naked-functions.rs:129:29
|
LL | pub unsafe fn rust_abi() {
| ^^^^^^^^
LL | pub unsafe extern "Rust" fn rust_abi() {
| ^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:170:1
--> $DIR/naked-functions.rs:169:1
|
LL | #[inline]
| ^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:177:1
--> $DIR/naked-functions.rs:176:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:184:1
--> $DIR/naked-functions.rs:183:1
|
LL | #[inline(never)]
| ^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:191:1
--> $DIR/naked-functions.rs:190:1
|
LL | #[inline]
| ^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:193:1
--> $DIR/naked-functions.rs:192:1
|
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^

error: naked functions cannot be inlined
--> $DIR/naked-functions.rs:195:1
--> $DIR/naked-functions.rs:194:1
|
LL | #[inline(never)]
| ^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/naked-invalid-attr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Checks that #[naked] attribute can be placed on function definitions only.
//
// needs-asm-support
#![feature(naked_functions)]

#![naked] //~ ERROR should be applied to a function definition

use std::arch::asm;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/asm/named-asm-labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// which causes less readable LLVM errors and in the worst cases causes ICEs
// or segfaults based on system dependent behavior and codegen flags.

#![feature(naked_functions, asm_const)]
#![feature(asm_const)]

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

Expand Down
Loading