diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-08 11:36:30 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-06-08 23:55:25 +0300 |
| commit | 74a6d1c821a37a407d2b2bc701d62d0b460b9215 (patch) | |
| tree | 0fb11c32bcc088719f9a54eeff4315d61507d505 | |
| parent | 8049e6199bad86d3148c94463216cc745db2d796 (diff) | |
Turn `#[allocator]` into a built-in attribute and rename it to `#[rustc_allocator]`
| -rw-r--r-- | src/liballoc/alloc.rs | 3 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/collect.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 1 | ||||
| -rw-r--r-- | src/test/codegen/function-arguments.rs | 4 | ||||
| -rw-r--r-- | src/test/run-pass/auxiliary/allocator-dummy.rs | 59 |
8 files changed, 13 insertions, 65 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index 41ff06d70ff..755feb84962 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -15,7 +15,8 @@ extern "Rust" { // them from the `#[global_allocator]` attribute if there is one, or uses the // default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`) // otherwise. - #[allocator] + #[cfg_attr(bootstrap, allocator)] + #[cfg_attr(not(bootstrap), rustc_allocator)] #[rustc_allocator_nounwind] fn __rust_alloc(size: usize, align: usize) -> *mut u8; #[rustc_allocator_nounwind] diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index bfc008e14a4..c530ac24275 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -79,7 +79,7 @@ #![feature(coerce_unsized)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] -#![feature(custom_attribute)] +#![cfg_attr(bootstrap, feature(custom_attribute))] #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] #![feature(fmt_internals)] diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 2aaf5ec775d..27ee664aa5f 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2574,7 +2574,7 @@ bitflags! { /// `#[cold]`: a hint to LLVM that this function, when called, is never on /// the hot path. const COLD = 1 << 0; - /// `#[allocator]`: a hint to LLVM that the pointer returned from this + /// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this /// function is never null. const ALLOCATOR = 1 << 1; /// `#[unwind]`: an indicator that this function may unwind despite what diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 2751cd0a37e..f738f90b31e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -2445,7 +2445,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen for attr in attrs.iter() { if attr.check_name(sym::cold) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD; - } else if attr.check_name(sym::allocator) { + } else if attr.check_name(sym::rustc_allocator) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR; } else if attr.check_name(sym::unwind) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::UNWIND; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b41b91c7631..ac4a7271221 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1331,6 +1331,11 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "internal implementation detail", cfg_fn!(rustc_attrs))), + (sym::rustc_allocator, Whitelisted, template!(Word), Gated(Stability::Unstable, + sym::rustc_attrs, + "internal implementation detail", + cfg_fn!(rustc_attrs))), + // FIXME: #14408 whitelist docs since rustdoc looks at them ( sym::doc, diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 49123e4cc30..224b85a11f9 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -513,6 +513,7 @@ symbols! { rust_2018_preview, rust_begin_unwind, rustc, + rustc_allocator, rustc_allocator_nounwind, rustc_allow_const_fn_ptr, rustc_args_required_const, diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index c2d697fd046..bd121ef24ad 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -2,7 +2,7 @@ // ignore-tidy-linelength #![crate_type = "lib"] -#![feature(custom_attribute)] +#![feature(rustc_attrs)] pub struct S { _field: [i32; 8], @@ -146,7 +146,7 @@ pub fn enum_id_2(x: Option<u8>) -> Option<u8> { // CHECK: noalias i8* @allocator() #[no_mangle] -#[allocator] +#[rustc_allocator] pub fn allocator() -> *const i8 { std::ptr::null() } diff --git a/src/test/run-pass/auxiliary/allocator-dummy.rs b/src/test/run-pass/auxiliary/allocator-dummy.rs deleted file mode 100644 index bedf3020c8b..00000000000 --- a/src/test/run-pass/auxiliary/allocator-dummy.rs +++ /dev/null @@ -1,59 +0,0 @@ -// no-prefer-dynamic - -#![feature(allocator, core_intrinsics, panic_unwind)] -#![allocator] -#![crate_type = "rlib"] -#![no_std] - -extern crate unwind; - -pub static mut HITS: usize = 0; - -type size_t = usize; - -extern { - fn malloc(size: usize) -> *mut u8; - fn free(ptr: *mut u8); - fn calloc(size: usize, amt: usize) -> *mut u8; - fn realloc(ptr: *mut u8, size: usize) -> *mut u8; -} - -#[no_mangle] -pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 { - unsafe { - HITS += 1; - malloc(size as size_t) as *mut u8 - } -} - -#[no_mangle] -pub extern fn __rust_allocate_zeroed(size: usize, _align: usize) -> *mut u8 { - unsafe { calloc(size as size_t, 1) as *mut u8 } -} - -#[no_mangle] -pub extern fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize) { - unsafe { - HITS += 1; - free(ptr as *mut _) - } -} - -#[no_mangle] -pub extern fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, - align: usize) -> *mut u8 { - unsafe { - realloc(ptr as *mut _, size as size_t) as *mut u8 - } -} - -#[no_mangle] -pub extern fn __rust_reallocate_inplace(ptr: *mut u8, old_size: usize, - size: usize, align: usize) -> usize { - unsafe { core::intrinsics::abort() } -} - -#[no_mangle] -pub extern fn __rust_usable_size(size: usize, align: usize) -> usize { - unsafe { core::intrinsics::abort() } -} |
