3
3
use std:: cmp:: Ordering ;
4
4
5
5
use cranelift_module:: * ;
6
+ use rustc_const_eval:: interpret:: CTFE_ALLOC_SALT ;
6
7
use rustc_data_structures:: fx:: FxHashSet ;
7
8
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
8
9
use rustc_middle:: mir:: interpret:: { AllocId , GlobalAlloc , Scalar , read_target_uint} ;
@@ -199,23 +200,20 @@ pub(crate) fn codegen_const_value<'tcx>(
199
200
}
200
201
} ,
201
202
ConstValue :: Indirect { alloc_id, offset } => CValue :: by_ref (
202
- pointer_for_allocation ( fx, alloc_id)
203
+ Pointer :: new ( pointer_for_allocation ( fx, alloc_id) )
203
204
. offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
204
205
layout,
205
206
) ,
206
207
ConstValue :: Slice { data, meta } => {
207
208
let alloc_id = fx. tcx . reserve_and_set_memory_alloc ( data) ;
208
- let ptr = pointer_for_allocation ( fx, alloc_id) . get_addr ( fx ) ;
209
+ let ptr = pointer_for_allocation ( fx, alloc_id) ;
209
210
let len = fx. bcx . ins ( ) . iconst ( fx. pointer_type , meta as i64 ) ;
210
211
CValue :: by_val_pair ( ptr, len, layout)
211
212
}
212
213
}
213
214
}
214
215
215
- fn pointer_for_allocation < ' tcx > (
216
- fx : & mut FunctionCx < ' _ , ' _ , ' tcx > ,
217
- alloc_id : AllocId ,
218
- ) -> crate :: pointer:: Pointer {
216
+ fn pointer_for_allocation < ' tcx > ( fx : & mut FunctionCx < ' _ , ' _ , ' tcx > , alloc_id : AllocId ) -> Value {
219
217
let alloc = fx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
220
218
let data_id =
221
219
data_id_for_alloc_id ( & mut fx. constants_cx , fx. module , alloc_id, alloc. inner ( ) . mutability ) ;
@@ -224,8 +222,7 @@ fn pointer_for_allocation<'tcx>(
224
222
if fx. clif_comments . enabled ( ) {
225
223
fx. add_comment ( local_data_id, format ! ( "{:?}" , alloc_id) ) ;
226
224
}
227
- let global_ptr = fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id) ;
228
- crate :: pointer:: Pointer :: new ( global_ptr)
225
+ fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
229
226
}
230
227
231
228
fn data_id_for_alloc_id (
@@ -251,6 +248,11 @@ pub(crate) fn data_id_for_vtable<'tcx>(
251
248
data_id_for_alloc_id ( cx, module, alloc_id, Mutability :: Not )
252
249
}
253
250
251
+ pub ( crate ) fn pointer_for_anonymous_str ( fx : & mut FunctionCx < ' _ , ' _ , ' _ > , msg : & str ) -> Value {
252
+ let alloc_id = fx. tcx . allocate_bytes_dedup ( msg. as_bytes ( ) , CTFE_ALLOC_SALT ) ;
253
+ pointer_for_allocation ( fx, alloc_id)
254
+ }
255
+
254
256
fn data_id_for_static (
255
257
tcx : TyCtxt < ' _ > ,
256
258
module : & mut dyn Module ,
0 commit comments