@@ -193,20 +193,21 @@ pub(crate) fn codegen_const_value<'tcx>(
193193 place. to_cvalue ( fx)
194194 }
195195 }
196- Scalar :: Ptr ( ptr) => {
197- let alloc_kind = fx. tcx . get_global_alloc ( ptr. alloc_id ) ;
196+ Scalar :: Ptr ( ptr, _size) => {
197+ let ( alloc_id, offset) = ptr. into_parts ( ) ; // we know the `offset` is relative
198+ let alloc_kind = fx. tcx . get_global_alloc ( alloc_id) ;
198199 let base_addr = match alloc_kind {
199200 Some ( GlobalAlloc :: Memory ( alloc) ) => {
200201 let data_id = data_id_for_alloc_id (
201202 & mut fx. constants_cx ,
202203 fx. module ,
203- ptr . alloc_id ,
204+ alloc_id,
204205 alloc. mutability ,
205206 ) ;
206207 let local_data_id =
207208 fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
208209 if fx. clif_comments . enabled ( ) {
209- fx. add_comment ( local_data_id, format ! ( "{:?}" , ptr . alloc_id) ) ;
210+ fx. add_comment ( local_data_id, format ! ( "{:?}" , alloc_id) ) ;
210211 }
211212 fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
212213 }
@@ -226,10 +227,10 @@ pub(crate) fn codegen_const_value<'tcx>(
226227 }
227228 fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
228229 }
229- None => bug ! ( "missing allocation {:?}" , ptr . alloc_id) ,
230+ None => bug ! ( "missing allocation {:?}" , alloc_id) ,
230231 } ;
231- let val = if ptr . offset . bytes ( ) != 0 {
232- fx. bcx . ins ( ) . iadd_imm ( base_addr, i64:: try_from ( ptr . offset . bytes ( ) ) . unwrap ( ) )
232+ let val = if offset. bytes ( ) != 0 {
233+ fx. bcx . ins ( ) . iadd_imm ( base_addr, i64:: try_from ( offset. bytes ( ) ) . unwrap ( ) )
233234 } else {
234235 base_addr
235236 } ;
@@ -406,7 +407,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
406407 let bytes = alloc. inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..alloc. len ( ) ) . to_vec ( ) ;
407408 data_ctx. define ( bytes. into_boxed_slice ( ) ) ;
408409
409- for & ( offset, ( _tag , reloc ) ) in alloc. relocations ( ) . iter ( ) {
410+ for & ( offset, alloc_id ) in alloc. relocations ( ) . iter ( ) {
410411 let addend = {
411412 let endianness = tcx. data_layout . endian ;
412413 let offset = offset. bytes ( ) as usize ;
@@ -417,7 +418,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
417418 read_target_uint ( endianness, bytes) . unwrap ( )
418419 } ;
419420
420- let reloc_target_alloc = tcx. get_global_alloc ( reloc ) . unwrap ( ) ;
421+ let reloc_target_alloc = tcx. get_global_alloc ( alloc_id ) . unwrap ( ) ;
421422 let data_id = match reloc_target_alloc {
422423 GlobalAlloc :: Function ( instance) => {
423424 assert_eq ! ( addend, 0 ) ;
@@ -427,7 +428,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
427428 continue ;
428429 }
429430 GlobalAlloc :: Memory ( target_alloc) => {
430- data_id_for_alloc_id ( cx, module, reloc , target_alloc. mutability )
431+ data_id_for_alloc_id ( cx, module, alloc_id , target_alloc. mutability )
431432 }
432433 GlobalAlloc :: Static ( def_id) => {
433434 if tcx. codegen_fn_attrs ( def_id) . flags . contains ( CodegenFnAttrFlags :: THREAD_LOCAL )
0 commit comments