@@ -193,20 +193,21 @@ pub(crate) fn codegen_const_value<'tcx>(
193
193
place. to_cvalue ( fx)
194
194
}
195
195
}
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) ;
198
199
let base_addr = match alloc_kind {
199
200
Some ( GlobalAlloc :: Memory ( alloc) ) => {
200
201
let data_id = data_id_for_alloc_id (
201
202
& mut fx. constants_cx ,
202
203
fx. module ,
203
- ptr . alloc_id ,
204
+ alloc_id,
204
205
alloc. mutability ,
205
206
) ;
206
207
let local_data_id =
207
208
fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
208
209
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) ) ;
210
211
}
211
212
fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
212
213
}
@@ -226,10 +227,10 @@ pub(crate) fn codegen_const_value<'tcx>(
226
227
}
227
228
fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
228
229
}
229
- None => bug ! ( "missing allocation {:?}" , ptr . alloc_id) ,
230
+ None => bug ! ( "missing allocation {:?}" , alloc_id) ,
230
231
} ;
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 ( ) )
233
234
} else {
234
235
base_addr
235
236
} ;
@@ -406,7 +407,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
406
407
let bytes = alloc. inspect_with_uninit_and_ptr_outside_interpreter ( 0 ..alloc. len ( ) ) . to_vec ( ) ;
407
408
data_ctx. define ( bytes. into_boxed_slice ( ) ) ;
408
409
409
- for & ( offset, ( _tag , reloc ) ) in alloc. relocations ( ) . iter ( ) {
410
+ for & ( offset, alloc_id ) in alloc. relocations ( ) . iter ( ) {
410
411
let addend = {
411
412
let endianness = tcx. data_layout . endian ;
412
413
let offset = offset. bytes ( ) as usize ;
@@ -417,7 +418,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
417
418
read_target_uint ( endianness, bytes) . unwrap ( )
418
419
} ;
419
420
420
- let reloc_target_alloc = tcx. get_global_alloc ( reloc ) . unwrap ( ) ;
421
+ let reloc_target_alloc = tcx. get_global_alloc ( alloc_id ) . unwrap ( ) ;
421
422
let data_id = match reloc_target_alloc {
422
423
GlobalAlloc :: Function ( instance) => {
423
424
assert_eq ! ( addend, 0 ) ;
@@ -427,7 +428,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
427
428
continue ;
428
429
}
429
430
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 )
431
432
}
432
433
GlobalAlloc :: Static ( def_id) => {
433
434
if tcx. codegen_fn_attrs ( def_id) . flags . contains ( CodegenFnAttrFlags :: THREAD_LOCAL )
0 commit comments