diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs index 9324f0c01156..4622348ef1db 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_allocator.rs @@ -10,6 +10,16 @@ impl NoArgsAttributeParser for RustcAllocatorParser { const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocator; } +pub(crate) struct RustcAllocatorZeroedParser; + +impl NoArgsAttributeParser for RustcAllocatorZeroedParser { + const PATH: &[Symbol] = &[sym::rustc_allocator_zeroed]; + const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; + const ALLOWED_TARGETS: AllowedTargets = + AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::ForeignFn)]); + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAllocatorZeroed; +} + pub(crate) struct RustcDeallocatorParser; impl NoArgsAttributeParser for RustcDeallocatorParser { diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 19e03f1ad3eb..7e69cbf1ff6d 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -65,7 +65,8 @@ use crate::attributes::proc_macro_attrs::{ use crate::attributes::prototype::CustomMirParser; use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser}; use crate::attributes::rustc_allocator::{ - RustcAllocatorParser, RustcDeallocatorParser, RustcReallocatorParser, + RustcAllocatorParser, RustcAllocatorZeroedParser, RustcDeallocatorParser, + RustcReallocatorParser, }; use crate::attributes::rustc_dump::{ RustcDumpDefParents, RustcDumpItemBounds, RustcDumpPredicates, RustcDumpUserArgs, @@ -277,6 +278,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 86ea1ac94b4e..1b0427e7e676 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -344,6 +344,9 @@ fn process_builtin_attrs( AttributeKind::RustcReallocator => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR } + AttributeKind::RustcAllocatorZeroed => { + codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED + } _ => {} } } @@ -354,9 +357,6 @@ fn process_builtin_attrs( match name { sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND, - sym::rustc_allocator_zeroed => { - codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED - } sym::patchable_function_entry => { codegen_fn_attrs.patchable_function_entry = parse_patchable_function_entry(tcx, attr); diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 95c4b28f1421..1c0562d38d8a 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -909,6 +909,9 @@ pub enum AttributeKind { /// Represents `#[rustc_allocator]` RustcAllocator, + /// Represents `#[rustc_allocator_zeroed]` + RustcAllocatorZeroed, + /// Represents `#[rustc_builtin_macro]`. RustcBuiltinMacro { builtin_name: Option, helper_attrs: ThinVec, span: Span }, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 0dd2cefc83cf..803aca49b406 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -98,6 +98,7 @@ impl AttributeKind { RecursionLimit { .. } => No, Repr { .. } => No, RustcAllocator => No, + RustcAllocatorZeroed => No, RustcBuiltinMacro { .. } => Yes, RustcCoherenceIsCore(..) => No, RustcDeallocator => No, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 4e904b6f11ad..ca0d6b90a1c4 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -317,6 +317,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::RustcDumpVtable(..) | AttributeKind::NeedsAllocator | AttributeKind::RustcAllocator + | AttributeKind::RustcAllocatorZeroed | AttributeKind::RustcDeallocator | AttributeKind::RustcReallocator ) => { /* do nothing */ } @@ -364,7 +365,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | sym::rustc_reservation_impl | sym::rustc_doc_primitive | sym::rustc_conversion_suggestion - | sym::rustc_allocator_zeroed | sym::rustc_allocator_zeroed_variant | sym::rustc_deprecated_safe_2024 | sym::rustc_test_marker