@@ -152,7 +152,7 @@ impl ConstCodegenMethods for CodegenCx<'_> {
152152 self . const_uint_big ( ty, i)
153153 }
154154 fn const_usize ( & self , i : u64 ) -> Self :: Value {
155- let ptr_size = self . tcx . data_layout . pointer_size . bits ( ) as u32 ;
155+ let ptr_size = self . tcx . data_layout . pointer_size ( ) . bits ( ) as u32 ;
156156 let t = SpirvType :: Integer ( ptr_size, false ) . def ( DUMMY_SP , self ) ;
157157 self . constant_int ( t, i. into ( ) )
158158 }
@@ -263,7 +263,7 @@ impl ConstCodegenMethods for CodegenCx<'_> {
263263 . try_read_from_const_alloc ( alloc, pointee)
264264 . unwrap_or_else ( || self . const_data_from_alloc ( alloc) ) ;
265265 let value = self . static_addr_of ( init, alloc. inner ( ) . align , None ) ;
266- ( value, AddressSpace :: DATA )
266+ ( value, AddressSpace :: ZERO )
267267 }
268268 GlobalAlloc :: Function { instance } => (
269269 self . get_fn_addr ( instance) ,
@@ -292,13 +292,41 @@ impl ConstCodegenMethods for CodegenCx<'_> {
292292 . try_read_from_const_alloc ( alloc, pointee)
293293 . unwrap_or_else ( || self . const_data_from_alloc ( alloc) ) ;
294294 let value = self . static_addr_of ( init, alloc. inner ( ) . align , None ) ;
295- ( value, AddressSpace :: DATA )
295+ ( value, AddressSpace :: ZERO )
296296 }
297297 GlobalAlloc :: Static ( def_id) => {
298298 assert ! ( self . tcx. is_static( def_id) ) ;
299299 assert ! ( !self . tcx. is_thread_local_static( def_id) ) ;
300- ( self . get_static ( def_id) , AddressSpace :: DATA )
300+ ( self . get_static ( def_id) , AddressSpace :: ZERO )
301301 }
302+ GlobalAlloc :: TypeId { .. } => {
303+ return if offset. bytes ( ) == 0 {
304+ self . constant_null ( ty)
305+ } else {
306+ let result = self . undef ( ty) ;
307+ self . zombie_no_span (
308+ result. def_cx ( self ) ,
309+ "pointer has non-null integer address" ,
310+ ) ;
311+ result
312+ } ;
313+ }
314+ // -----------------------------------------------------------------------------
315+ // // gcc
316+ // + GlobalAlloc::TypeId { .. } => {
317+ // + let val = self.const_usize(offset.bytes());
318+ // + // This is still a variable of pointer type, even though we only use the provenance
319+ // + // of that pointer in CTFE and Miri. But to make LLVM's type system happy,
320+ // + // we need an int-to-ptr cast here (it doesn't matter at all which provenance that picks).
321+ // + return self.context.new_cast(None, val, ty);
322+ // + }
323+ // -----------------------------------------------------------------------------
324+ // // llvm
325+ // + // Drop the provenance, the offset contains the bytes of the hash
326+ // + let llval = self.const_usize(offset.bytes());
327+ // + return unsafe { llvm::LLVMConstIntToPtr(llval, llty) };
328+
329+ // -----------------------------------------------------------------------------
302330 } ;
303331 self . const_bitcast ( self . const_ptr_byte_offset ( base_addr, offset) , ty)
304332 }
@@ -430,7 +458,7 @@ impl<'tcx> CodegenCx<'tcx> {
430458 . fatal ( format ! ( "invalid size for float: {other}" ) ) ;
431459 }
432460 } ) ,
433- SpirvType :: Pointer { .. } => Primitive :: Pointer ( AddressSpace :: DATA ) ,
461+ SpirvType :: Pointer { .. } => Primitive :: Pointer ( AddressSpace :: ZERO ) ,
434462 _ => unreachable ! ( ) ,
435463 } ;
436464
0 commit comments