Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions crates/rustc_codegen_spirv/src/builder/builder_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let stride = ty_kind.sizeof(self)?;
ty_size = MaybeSized::Sized(stride);

indices.push((offset.bytes() / stride.bytes()).try_into().ok()?);
offset = Size::from_bytes(offset.bytes() % stride.bytes());
if stride == Size::ZERO {
if offset != Size::ZERO {
trace!("zero-sized element with non-zero offset: {:?}", offset);
return None;
}

indices.push(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, got a conflict locally when rebasing on top of this PR, turns out I had a commit that included the indices.push(0); (but not the check - so I resolved the conflict by keeping the main version, i.e. the one from this PR), so that's probably an extra point in the favor of this being correct.

offset = Size::ZERO;
} else {
indices.push((offset.bytes() / stride.bytes()).try_into().ok()?);
offset = Size::from_bytes(offset.bytes() % stride.bytes());
}
}
_ => {
trace!("recovering access chain from SOMETHING ELSE, RETURNING NONE");
Expand Down
15 changes: 15 additions & 0 deletions tests/compiletests/ui/lang/core/issue-424.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// build-pass

#![no_std]

use core::marker::PhantomData;
use spirv_std::spirv;

pub struct BitSlice<T, O> {
_ord: PhantomData<O>,
_typ: PhantomData<[T]>,
_mem: [()],
}

#[spirv(compute(threads(1)))]
pub fn issue424() {}