@@ -4,7 +4,7 @@ use std::borrow::Borrow;
4
4
5
5
use libc:: { c_char, c_uint} ;
6
6
use rustc_abi:: Primitive :: Pointer ;
7
- use rustc_abi:: { self as abi, Align , HasDataLayout , Size } ;
7
+ use rustc_abi:: { self as abi, Align , HasDataLayout as _ , Size } ;
8
8
use rustc_ast:: Mutability ;
9
9
use rustc_codegen_ssa:: common:: TypeKind ;
10
10
use rustc_codegen_ssa:: traits:: * ;
@@ -319,17 +319,16 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
319
319
) ) )
320
320
. unwrap_memory ( ) ;
321
321
let init = const_alloc_to_llvm ( self , alloc. inner ( ) , /*static*/ false ) ;
322
- let value = self . static_addr_of_impl ( init, alloc. inner ( ) . align , None ) ;
323
- value
322
+ self . static_addr_of_impl ( init, alloc. inner ( ) . align , None )
324
323
}
325
324
GlobalAlloc :: Static ( def_id) => {
326
325
assert ! ( self . tcx. is_static( def_id) ) ;
327
326
assert ! ( !self . tcx. is_thread_local_static( def_id) ) ;
328
327
self . get_static ( def_id)
329
328
}
330
- GlobalAlloc :: Type ( ty ) => {
329
+ GlobalAlloc :: Type { ty , segment } => {
331
330
let type_id = self . tcx . type_id_hash ( ty) . as_u128 ( ) ;
332
- let mut alloc = Allocation :: new (
331
+ let mut alloc: Allocation = Allocation :: new (
333
332
Size :: from_bytes ( 16 ) ,
334
333
Align :: from_bytes ( 8 ) . unwrap ( ) ,
335
334
AllocInit :: Uninit ,
@@ -342,17 +341,13 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
342
341
Scalar :: from_u128 ( type_id) ,
343
342
)
344
343
. unwrap ( ) ;
345
- alloc. mutability = Mutability :: Not ;
346
- let init = const_alloc_to_llvm ( self , & alloc, /*static*/ false ) ;
347
- self . static_addr_of_impl ( init, alloc. align , None )
348
- }
349
- GlobalAlloc :: PartialHash ( ty) => {
350
- assert ! ( matches!( layout. primitive( ) , Pointer ( _) ) ) ;
351
- let bytes = self . tcx . type_id_hash ( ty) . truncate ( ) . as_u64 ( ) . to_be_bytes ( ) ;
352
- let bits = self . tcx . data_layout . pointer_size . bits ( ) ;
353
- let mask = u64:: MAX >> ( 64 - bits) ;
354
- // It doesn't matter which bits we pick as long as the scheme is the same with the same compiler.
355
- let llval = self . const_usize ( u64:: from_be_bytes ( bytes) & mask) ;
344
+ let pointer_size = self . tcx . data_layout . pointer_size ;
345
+ let offset = pointer_size * u64:: from ( segment) ;
346
+ let value = alloc
347
+ . read_scalar ( & self . tcx , alloc_range ( offset, pointer_size) , false )
348
+ . unwrap ( ) ;
349
+ let data = value. to_bits ( pointer_size) . unwrap ( ) as u64 ;
350
+ let llval = self . const_usize ( data) ;
356
351
return unsafe { llvm:: LLVMConstIntToPtr ( llval, llty) } ;
357
352
}
358
353
} ;
0 commit comments