3
3
4
4
use crate :: prelude:: * ;
5
5
6
- use rustc_ast:: expand:: allocator:: { AllocatorKind , AllocatorTy , ALLOCATOR_METHODS } ;
6
+ use rustc_ast:: expand:: allocator:: {
7
+ alloc_error_handler_name, AllocatorKind , AllocatorTy , ALLOCATOR_METHODS ,
8
+ } ;
7
9
use rustc_codegen_ssa:: base:: allocator_kind_for_codegen;
8
10
use rustc_session:: config:: OomStrategy ;
9
- use rustc_span:: symbol:: sym;
10
11
11
12
/// Returns whether an allocator shim was created
12
13
pub ( crate ) fn codegen (
@@ -34,41 +35,43 @@ fn codegen_inner(
34
35
) {
35
36
let usize_ty = module. target_config ( ) . pointer_type ( ) ;
36
37
37
- for method in ALLOCATOR_METHODS {
38
- let mut arg_tys = Vec :: with_capacity ( method. inputs . len ( ) ) ;
39
- for ty in method. inputs . iter ( ) {
40
- match * ty {
41
- AllocatorTy :: Layout => {
42
- arg_tys. push ( usize_ty) ; // size
43
- arg_tys. push ( usize_ty) ; // align
44
- }
45
- AllocatorTy :: Ptr => arg_tys. push ( usize_ty) ,
46
- AllocatorTy :: Usize => arg_tys. push ( usize_ty) ,
38
+ if kind == AllocatorKind :: Default {
39
+ for method in ALLOCATOR_METHODS {
40
+ let mut arg_tys = Vec :: with_capacity ( method. inputs . len ( ) ) ;
41
+ for ty in method. inputs . iter ( ) {
42
+ match * ty {
43
+ AllocatorTy :: Layout => {
44
+ arg_tys. push ( usize_ty) ; // size
45
+ arg_tys. push ( usize_ty) ; // align
46
+ }
47
+ AllocatorTy :: Ptr => arg_tys. push ( usize_ty) ,
48
+ AllocatorTy :: Usize => arg_tys. push ( usize_ty) ,
47
49
48
- AllocatorTy :: ResultPtr | AllocatorTy :: Unit => panic ! ( "invalid allocator arg" ) ,
50
+ AllocatorTy :: ResultPtr | AllocatorTy :: Unit => panic ! ( "invalid allocator arg" ) ,
51
+ }
49
52
}
50
- }
51
- let output = match method. output {
52
- AllocatorTy :: ResultPtr => Some ( usize_ty) ,
53
- AllocatorTy :: Unit => None ,
53
+ let output = match method. output {
54
+ AllocatorTy :: ResultPtr => Some ( usize_ty) ,
55
+ AllocatorTy :: Unit => None ,
54
56
55
- AllocatorTy :: Layout | AllocatorTy :: Usize | AllocatorTy :: Ptr => {
56
- panic ! ( "invalid allocator output" )
57
- }
58
- } ;
57
+ AllocatorTy :: Layout | AllocatorTy :: Usize | AllocatorTy :: Ptr => {
58
+ panic ! ( "invalid allocator output" )
59
+ }
60
+ } ;
59
61
60
- let sig = Signature {
61
- call_conv : module. target_config ( ) . default_call_conv ,
62
- params : arg_tys. iter ( ) . cloned ( ) . map ( AbiParam :: new) . collect ( ) ,
63
- returns : output. into_iter ( ) . map ( AbiParam :: new) . collect ( ) ,
64
- } ;
65
- crate :: common:: create_wrapper_function (
66
- module,
67
- unwind_context,
68
- sig,
69
- & format ! ( "__rust_{}" , method. name) ,
70
- & kind. fn_name ( method. name ) ,
71
- ) ;
62
+ let sig = Signature {
63
+ call_conv : module. target_config ( ) . default_call_conv ,
64
+ params : arg_tys. iter ( ) . cloned ( ) . map ( AbiParam :: new) . collect ( ) ,
65
+ returns : output. into_iter ( ) . map ( AbiParam :: new) . collect ( ) ,
66
+ } ;
67
+ crate :: common:: create_wrapper_function (
68
+ module,
69
+ unwind_context,
70
+ sig,
71
+ & format ! ( "__rust_{}" , method. name) ,
72
+ & AllocatorKind :: Default . fn_name ( method. name ) ,
73
+ ) ;
74
+ }
72
75
}
73
76
74
77
let sig = Signature {
@@ -81,7 +84,7 @@ fn codegen_inner(
81
84
unwind_context,
82
85
sig,
83
86
"__rust_alloc_error_handler" ,
84
- & alloc_error_handler_kind . fn_name ( sym :: oom ) ,
87
+ & alloc_error_handler_name ( alloc_error_handler_kind ) ,
85
88
) ;
86
89
87
90
let data_id = module. declare_data ( OomStrategy :: SYMBOL , Linkage :: Export , false , false ) . unwrap ( ) ;
0 commit comments