@@ -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,12 +292,24 @@ 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 )
301+ }
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+ } ;
301313 }
302314 } ;
303315 self . const_bitcast ( self . const_ptr_byte_offset ( base_addr, offset) , ty)
@@ -430,7 +442,7 @@ impl<'tcx> CodegenCx<'tcx> {
430442 . fatal ( format ! ( "invalid size for float: {other}" ) ) ;
431443 }
432444 } ) ,
433- SpirvType :: Pointer { .. } => Primitive :: Pointer ( AddressSpace :: DATA ) ,
445+ SpirvType :: Pointer { .. } => Primitive :: Pointer ( AddressSpace :: ZERO ) ,
434446 _ => unreachable ! ( ) ,
435447 } ;
436448
0 commit comments