File tree Expand file tree Collapse file tree
crates/rustc_codegen_spirv/src/codegen_cx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -622,7 +622,33 @@ impl<'tcx> CodegenCx<'tcx> {
622622 }
623623 SpirvType :: RuntimeArray { element } => {
624624 let stride = self . lookup_type ( element) . sizeof ( self ) . unwrap ( ) ;
625- let count = ( alloc. inner ( ) . size ( ) - offset) . bytes ( ) / stride. bytes ( ) ;
625+ if stride. bytes ( ) == 0 {
626+ let result = self . undef ( ty) ;
627+ self . zombie_no_span (
628+ result. def_cx ( self ) ,
629+ & format ! (
630+ "unsupported unsized `{}` constant with zero-sized elements" ,
631+ self . debug_type( ty)
632+ ) ,
633+ ) ;
634+ return ( result, Size :: ZERO ) ;
635+ }
636+
637+ let read_size = alloc. inner ( ) . size ( ) - offset;
638+ let rem = read_size. bytes ( ) % stride. bytes ( ) ;
639+ if rem != 0 {
640+ let result = self . undef ( ty) ;
641+ self . zombie_no_span (
642+ result. def_cx ( self ) ,
643+ & format ! (
644+ "unsupported unsized `{}` constant with {rem} trailing bytes" ,
645+ self . debug_type( ty)
646+ ) ,
647+ ) ;
648+ return ( result, read_size) ;
649+ }
650+
651+ let count = read_size. bytes ( ) / stride. bytes ( ) ;
626652 let sized_ty = self . type_array ( element, count) ;
627653
628654 let result = self . constant_composite (
You can’t perform that action at this time.
0 commit comments