Make #[naked]
an unsafe attribute
This commit is contained in:
parent
191df20fca
commit
41ddf86722
46 changed files with 375 additions and 403 deletions
|
@ -247,9 +247,9 @@ builtin_macros_multiple_defaults = multiple declared defaults
|
|||
.suggestion = make `{$ident}` default
|
||||
|
||||
builtin_macros_naked_functions_testing_attribute =
|
||||
cannot use `#[naked]` with testing attributes
|
||||
cannot use `#[unsafe(naked)]` with testing attributes
|
||||
.label = function marked with testing attribute here
|
||||
.naked_attribute = `#[naked]` is incompatible with testing attributes
|
||||
.naked_attribute = `#[unsafe(naked)]` is incompatible with testing attributes
|
||||
|
||||
builtin_macros_no_default_variant = `#[derive(Default)]` on enum with no `#[default]`
|
||||
.label = this enum needs a unit variant marked with `#[default]`
|
||||
|
|
|
@ -387,11 +387,9 @@ global_asm! {
|
|||
}
|
||||
|
||||
#[cfg(all(not(jit), target_arch = "x86_64"))]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
extern "C" fn naked_test() {
|
||||
unsafe {
|
||||
naked_asm!("ret");
|
||||
}
|
||||
naked_asm!("ret")
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
|
@ -11,7 +11,7 @@ Erroneous code example:
|
|||
|
||||
```compile_fail,E0736
|
||||
#[inline]
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
fn foo() {}
|
||||
```
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ Erroneous code example:
|
|||
```compile_fail,E0787
|
||||
#![feature(naked_functions)]
|
||||
|
||||
#[naked]
|
||||
#[unsafe(naked)]
|
||||
pub extern "C" fn f() -> u32 {
|
||||
42
|
||||
}
|
||||
|
|
|
@ -517,7 +517,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
|
|||
|
||||
// Linking:
|
||||
gated!(
|
||||
naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
|
||||
unsafe naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
|
||||
naked_functions, experimental!(naked)
|
||||
),
|
||||
|
||||
|
|
|
@ -564,13 +564,17 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
ExprKind::InlineAsm(box InlineAsmExpr {
|
||||
asm_macro: AsmMacro::Asm | AsmMacro::NakedAsm,
|
||||
asm_macro: asm_macro @ (AsmMacro::Asm | AsmMacro::NakedAsm),
|
||||
ref operands,
|
||||
template: _,
|
||||
options: _,
|
||||
line_spans: _,
|
||||
}) => {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
// The `naked` attribute and the `naked_asm!` block form one atomic unit of
|
||||
// unsafety, and `naked_asm!` does not itself need to be wrapped in an unsafe block.
|
||||
if let AsmMacro::Asm = asm_macro {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
}
|
||||
|
||||
// For inline asm, do not use `walk_expr`, since we want to handle the label block
|
||||
// specially.
|
||||
|
|
|
@ -194,12 +194,6 @@ pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr:
|
|||
}
|
||||
}
|
||||
} else if let Safety::Unsafe(unsafe_span) = attr_item.unsafety {
|
||||
// Allow (but don't require) `#[unsafe(naked)]` so that compiler-builtins can upgrade to it.
|
||||
// FIXME(#139797): remove this special case when compiler-builtins has upgraded.
|
||||
if attr.has_name(sym::naked) {
|
||||
return;
|
||||
}
|
||||
|
||||
psess.dcx().emit_err(errors::InvalidAttrUnsafe {
|
||||
span: unsafe_span,
|
||||
name: attr_item.path.clone(),
|
||||
|
|
|
@ -508,7 +508,7 @@ passes_must_use_no_effect =
|
|||
`#[must_use]` has no effect when applied to {$article} {$target}
|
||||
|
||||
passes_naked_asm_outside_naked_fn =
|
||||
the `naked_asm!` macro can only be used in functions marked with `#[naked]`
|
||||
the `naked_asm!` macro can only be used in functions marked with `#[unsafe(naked)]`
|
||||
|
||||
passes_naked_functions_asm_block =
|
||||
naked functions must contain a single `naked_asm!` invocation
|
||||
|
@ -516,9 +516,9 @@ passes_naked_functions_asm_block =
|
|||
.label_non_asm = not allowed in naked functions
|
||||
|
||||
passes_naked_functions_incompatible_attribute =
|
||||
attribute incompatible with `#[naked]`
|
||||
.label = the `{$attr}` attribute is incompatible with `#[naked]`
|
||||
.naked_attribute = function marked with `#[naked]` here
|
||||
attribute incompatible with `#[unsafe(naked)]`
|
||||
.label = the `{$attr}` attribute is incompatible with `#[unsafe(naked)]`
|
||||
.naked_attribute = function marked with `#[unsafe(naked)]` here
|
||||
|
||||
passes_naked_functions_must_naked_asm =
|
||||
the `asm!` macro is not allowed in naked functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue