@@ -27,16 +27,23 @@ extern "Rust" {
2727 // (the code expanding that attribute macro generates those functions), or to call
2828 // the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
2929 // otherwise.
30- // The rustc fork of LLVM also special-cases these function names to be able to optimize them
30+ // The rustc fork of LLVM 14 and earlier also special-cases these function names to be able to optimize them
3131 // like `malloc`, `realloc`, and `free`, respectively.
3232 #[ rustc_allocator]
33- #[ rustc_allocator_nounwind]
33+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
34+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
3435 fn __rust_alloc ( size : usize , align : usize ) -> * mut u8 ;
35- #[ rustc_allocator_nounwind]
36+ #[ rustc_deallocator]
37+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
38+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
3639 fn __rust_dealloc ( ptr : * mut u8 , size : usize , align : usize ) ;
37- #[ rustc_allocator_nounwind]
40+ #[ rustc_reallocator]
41+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
42+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
3843 fn __rust_realloc ( ptr : * mut u8 , old_size : usize , align : usize , new_size : usize ) -> * mut u8 ;
39- #[ rustc_allocator_nounwind]
44+ #[ rustc_allocator_zeroed]
45+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
46+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
4047 fn __rust_alloc_zeroed ( size : usize , align : usize ) -> * mut u8 ;
4148}
4249
@@ -72,11 +79,14 @@ pub use std::alloc::Global;
7279/// # Examples
7380///
7481/// ```
75- /// use std::alloc::{alloc, dealloc, Layout};
82+ /// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
7683///
7784/// unsafe {
7885/// let layout = Layout::new::<u16>();
7986/// let ptr = alloc(layout);
87+ /// if ptr.is_null() {
88+ /// handle_alloc_error(layout);
89+ /// }
8090///
8191/// *(ptr as *mut u16) = 42;
8292/// assert_eq!(*(ptr as *mut u16), 42);
@@ -400,13 +410,13 @@ pub mod __alloc_error_handler {
400410
401411 // if there is no `#[alloc_error_handler]`
402412 #[ rustc_std_internal_symbol]
403- pub unsafe extern "C-unwind" fn __rdl_oom ( size : usize , _align : usize ) -> ! {
413+ pub unsafe fn __rdl_oom ( size : usize , _align : usize ) -> ! {
404414 panic ! ( "memory allocation of {size} bytes failed" )
405415 }
406416
407417 // if there is an `#[alloc_error_handler]`
408418 #[ rustc_std_internal_symbol]
409- pub unsafe extern "C-unwind" fn __rg_oom ( size : usize , align : usize ) -> ! {
419+ pub unsafe fn __rg_oom ( size : usize , align : usize ) -> ! {
410420 let layout = unsafe { Layout :: from_size_align_unchecked ( size, align) } ;
411421 extern "Rust" {
412422 #[ lang = "oom" ]
0 commit comments