33use std:: cmp:: Ordering ;
44
55use cranelift_module:: * ;
6+ use rustc_const_eval:: interpret:: CTFE_ALLOC_SALT ;
67use rustc_data_structures:: fx:: FxHashSet ;
78use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
89use rustc_middle:: mir:: interpret:: { AllocId , GlobalAlloc , Scalar , read_target_uint} ;
@@ -199,23 +200,20 @@ pub(crate) fn codegen_const_value<'tcx>(
199200 }
200201 } ,
201202 ConstValue :: Indirect { alloc_id, offset } => CValue :: by_ref (
202- pointer_for_allocation ( fx, alloc_id)
203+ Pointer :: new ( pointer_for_allocation ( fx, alloc_id) )
203204 . offset_i64 ( fx, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) ) ,
204205 layout,
205206 ) ,
206207 ConstValue :: Slice { data, meta } => {
207208 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) ;
209210 let len = fx. bcx . ins ( ) . iconst ( fx. pointer_type , meta as i64 ) ;
210211 CValue :: by_val_pair ( ptr, len, layout)
211212 }
212213 }
213214}
214215
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 {
219217 let alloc = fx. tcx . global_alloc ( alloc_id) . unwrap_memory ( ) ;
220218 let data_id =
221219 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>(
224222 if fx. clif_comments . enabled ( ) {
225223 fx. add_comment ( local_data_id, format ! ( "{:?}" , alloc_id) ) ;
226224 }
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)
229226}
230227
231228fn data_id_for_alloc_id (
@@ -251,6 +248,11 @@ pub(crate) fn data_id_for_vtable<'tcx>(
251248 data_id_for_alloc_id ( cx, module, alloc_id, Mutability :: Not )
252249}
253250
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+
254256fn data_id_for_static (
255257 tcx : TyCtxt < ' _ > ,
256258 module : & mut dyn Module ,
0 commit comments