@@ -27,16 +27,23 @@ extern "Rust" {
27
27
// (the code expanding that attribute macro generates those functions), or to call
28
28
// the default implementations in libstd (`__rdl_alloc` etc. in `library/std/src/alloc.rs`)
29
29
// 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
31
31
// like `malloc`, `realloc`, and `free`, respectively.
32
32
#[ rustc_allocator]
33
- #[ rustc_allocator_nounwind]
33
+ #[ cfg_attr( not( bootstrap) , rustc_nounwind) ]
34
+ #[ cfg_attr( bootstrap, rustc_allocator_nounwind) ]
34
35
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) ]
36
39
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) ]
38
43
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) ]
40
47
fn __rust_alloc_zeroed ( size : usize , align : usize ) -> * mut u8 ;
41
48
}
42
49
@@ -72,11 +79,14 @@ pub use std::alloc::Global;
72
79
/// # Examples
73
80
///
74
81
/// ```
75
- /// use std::alloc::{alloc, dealloc, Layout};
82
+ /// use std::alloc::{alloc, dealloc, handle_alloc_error, Layout};
76
83
///
77
84
/// unsafe {
78
85
/// let layout = Layout::new::<u16>();
79
86
/// let ptr = alloc(layout);
87
+ /// if ptr.is_null() {
88
+ /// handle_alloc_error(layout);
89
+ /// }
80
90
///
81
91
/// *(ptr as *mut u16) = 42;
82
92
/// assert_eq!(*(ptr as *mut u16), 42);
@@ -400,13 +410,13 @@ pub mod __alloc_error_handler {
400
410
401
411
// if there is no `#[alloc_error_handler]`
402
412
#[ 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 ) -> ! {
404
414
panic ! ( "memory allocation of {size} bytes failed" )
405
415
}
406
416
407
417
// if there is an `#[alloc_error_handler]`
408
418
#[ 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 ) -> ! {
410
420
let layout = unsafe { Layout :: from_size_align_unchecked ( size, align) } ;
411
421
extern "Rust" {
412
422
#[ lang = "oom" ]
0 commit comments