diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index a40da4cc5b..1ae9b7f68c 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -412,6 +412,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if field_ty_kind .sizeof(self) .map_or(true, |size| offset_in_field < size) + // If the field is a zero sized type, check the type to + // get the correct entry + || offset_in_field == Size::ZERO && leaf_ty == field_ty { Some((i, field_ty, field_ty_kind, offset_in_field)) } else { diff --git a/tests/ui/lang/core/ref/zst_member_ref_arg.rs b/tests/ui/lang/core/ref/zst_member_ref_arg.rs new file mode 100644 index 0000000000..2192e407db --- /dev/null +++ b/tests/ui/lang/core/ref/zst_member_ref_arg.rs @@ -0,0 +1,18 @@ +// build-pass + +use spirv_std as _; +struct A; +struct B; + +struct S { + x: A, + y: B, +} + +fn f(x: &B) {} + +#[spirv(fragment)] +pub fn main() { + let s = S { x: A, y: B }; + f(&s.y); +}