Skip to content

Commit 044f567

Browse files
committed
Allow zero stride when offset is also zero
1 parent e87c324 commit 044f567

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
438438
ty_kind = self.lookup_type(ty);
439439

440440
let stride = ty_kind.sizeof(self)?;
441-
indices.push((offset.bytes() / stride.bytes()).try_into().ok()?);
442-
offset = Size::from_bytes(offset.bytes() % stride.bytes());
441+
if stride.bytes() != 0 {
442+
indices.push((offset.bytes() / stride.bytes()).try_into().ok()?);
443+
offset = Size::from_bytes(offset.bytes() % stride.bytes());
444+
} else if offset.bytes() == 0 {
445+
indices.push(0);
446+
offset = Size::from_bytes(0);
447+
} else {
448+
panic!("Non-zero offset over zero stride.");
449+
}
443450
}
444451
_ => return None,
445452
}

0 commit comments

Comments
 (0)