@@ -4,7 +4,7 @@ use std::borrow::Borrow;
44
55use  libc:: { c_char,  c_uint} ; 
66use  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 } ; 
88use  rustc_ast:: Mutability ; 
99use  rustc_codegen_ssa:: common:: TypeKind ; 
1010use  rustc_codegen_ssa:: traits:: * ; 
@@ -319,17 +319,16 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
319319                            ) ) ) 
320320                            . unwrap_memory ( ) ; 
321321                        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 ) 
324323                    } 
325324                    GlobalAlloc :: Static ( def_id)  => { 
326325                        assert ! ( self . tcx. is_static( def_id) ) ; 
327326                        assert ! ( !self . tcx. is_thread_local_static( def_id) ) ; 
328327                        self . get_static ( def_id) 
329328                    } 
330-                     GlobalAlloc :: Type ( ty )  => { 
329+                     GlobalAlloc :: Type   {  ty ,  segment  }  => { 
331330                        let  type_id = self . tcx . type_id_hash ( ty) . as_u128 ( ) ; 
332-                         let  mut  alloc = Allocation :: new ( 
331+                         let  mut  alloc:   Allocation  = Allocation :: new ( 
333332                            Size :: from_bytes ( 16 ) , 
334333                            Align :: from_bytes ( 8 ) . unwrap ( ) , 
335334                            AllocInit :: Uninit , 
@@ -342,17 +341,13 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
342341                                Scalar :: from_u128 ( type_id) , 
343342                            ) 
344343                            . 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) ; 
356351                        return  unsafe  {  llvm:: LLVMConstIntToPtr ( llval,  llty)  } ; 
357352                    } 
358353                } ; 
0 commit comments