@@ -91,32 +91,47 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
91
91
let value = & this. thir [ value] ;
92
92
let tcx = this. tcx ;
93
93
94
- let u8_ptr = tcx. mk_mut_ptr ( tcx. mk_mach_uint ( ty:: UintTy :: U8 ) ) ;
95
- let storage = this. local_decls . push ( LocalDecl :: new ( u8_ptr, expr_span) . internal ( ) ) ;
96
- this. cfg . push (
94
+ let fake_scope = this. new_source_scope (
95
+ expr_span,
96
+ LintLevel :: Inherited ,
97
+ Some ( Safety :: BuiltinUnsafe ) ,
98
+ ) ;
99
+ let fake_info = SourceInfo { span : expr_span, scope : fake_scope } ;
100
+
101
+ let size = this. temp ( tcx. types . usize , expr_span) ;
102
+ this. cfg . push_assign (
97
103
block,
98
- Statement { source_info, kind : StatementKind :: StorageLive ( storage) } ,
104
+ fake_info,
105
+ size,
106
+ Rvalue :: NullaryOp ( NullOp :: SizeOf , value. ty ) ,
99
107
) ;
100
108
101
- let box_new = tcx . require_lang_item ( LangItem :: BoxNew , Some ( source_info . span ) ) ;
102
- let box_new = Operand :: function_handle (
103
- tcx ,
104
- box_new ,
105
- tcx . mk_substs ( [ value . ty . into ( ) ] . iter ( ) ) ,
106
- source_info . span ,
109
+ let align = this . temp ( tcx . types . usize , expr_span ) ;
110
+ this . cfg . push_assign (
111
+ block ,
112
+ fake_info ,
113
+ align ,
114
+ Rvalue :: NullaryOp ( NullOp :: AlignOf , value . ty ) ,
107
115
) ;
108
116
117
+ let exchange_malloc = Operand :: function_handle (
118
+ tcx,
119
+ tcx. require_lang_item ( LangItem :: ExchangeMalloc , Some ( expr_span) ) ,
120
+ ty:: List :: empty ( ) ,
121
+ expr_span,
122
+ ) ;
123
+ let storage = this. temp ( tcx. mk_mut_ptr ( tcx. types . u8 ) , expr_span) ;
109
124
let success = this. cfg . start_new_block ( ) ;
110
125
this. cfg . terminate (
111
126
block,
112
- source_info ,
127
+ fake_info ,
113
128
TerminatorKind :: Call {
114
- func : box_new ,
115
- args : Vec :: new ( ) ,
129
+ func : exchange_malloc ,
130
+ args : vec ! [ Operand :: Move ( size ) , Operand :: Move ( align ) ] ,
116
131
destination : Some ( ( Place :: from ( storage) , success) ) ,
117
132
cleanup : None ,
118
133
from_hir_call : false ,
119
- fn_span : source_info . span ,
134
+ fn_span : expr_span ,
120
135
} ,
121
136
) ;
122
137
this. diverge_from ( block) ;
0 commit comments