Skip to content

Commit d45070f

Browse files
committed
abi layout: limit vectors to at most 4 components, as spec states
1 parent afb3a7e commit d45070f

File tree

1 file changed

+15
-12
lines changed
  • crates/rustc_codegen_spirv/src

1 file changed

+15
-12
lines changed

crates/rustc_codegen_spirv/src/abi.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -964,15 +964,18 @@ fn trans_intrinsic_type<'tcx>(
964964
}
965965
IntrinsicType::Matrix => {
966966
let span = span_for_spirv_type_adt(cx, ty).unwrap();
967-
let (element, count) =
968-
trans_glam_like_struct(cx, span, ty, args, "`#[spirv(matrix)]`")?;
967+
let err_attr_name = "`#[spirv(matrix)]`";
968+
let (element, count) = trans_glam_like_struct(cx, span, ty, args, err_attr_name)?;
969969
match cx.lookup_type(element) {
970970
SpirvType::Vector { .. } => (),
971971
ty => {
972972
return Err(cx
973973
.tcx
974974
.dcx()
975-
.struct_span_err(span, "`#[spirv(matrix)]` type fields must all be vectors")
975+
.struct_span_err(
976+
span,
977+
format!("{err_attr_name} type fields must all be vectors"),
978+
)
976979
.with_note(format!("field type is {}", ty.debug(element, cx)))
977980
.emit());
978981
}
@@ -981,8 +984,8 @@ fn trans_intrinsic_type<'tcx>(
981984
}
982985
IntrinsicType::Vector => {
983986
let span = span_for_spirv_type_adt(cx, ty).unwrap();
984-
let (element, count) =
985-
trans_glam_like_struct(cx, span, ty, args, "`#[spirv(vector)]`")?;
987+
let err_attr_name = "`#[spirv(vector)]`";
988+
let (element, count) = trans_glam_like_struct(cx, span, ty, args, err_attr_name)?;
986989
match cx.lookup_type(element) {
987990
SpirvType::Bool | SpirvType::Float { .. } | SpirvType::Integer { .. } => (),
988991
ty => {
@@ -991,7 +994,9 @@ fn trans_intrinsic_type<'tcx>(
991994
.dcx()
992995
.struct_span_err(
993996
span,
994-
"`#[spirv(vector)]` type fields must all be floats, integers or bools",
997+
format!(
998+
"{err_attr_name} type fields must all be floats, integers or bools"
999+
),
9951000
)
9961001
.with_note(format!("field type is {}", ty.debug(element, cx)))
9971002
.emit());
@@ -1039,18 +1044,16 @@ fn trans_glam_like_struct<'tcx>(
10391044
let element_word = element.spirv_type(span, cx);
10401045
let count = u32::try_from(count)
10411046
.ok()
1042-
.filter(|count| *count >= 2)
1047+
.filter(|count| 2 <= *count && *count <= 4)
10431048
.ok_or_else(|| {
1044-
tcx.dcx().span_err(
1045-
span,
1046-
format!("{err_attr_name} must have at least 2 members"),
1047-
)
1049+
tcx.dcx()
1050+
.span_err(span, format!("{err_attr_name} must have 2, 3 or 4 members"))
10481051
})?;
10491052

10501053
Ok((element_word, count))
10511054
} else {
10521055
Err(tcx
10531056
.dcx()
1054-
.span_err(span, "#[spirv(vector)] type must be a struct"))
1057+
.span_err(span, format!("{err_attr_name} type must be a struct")))
10551058
}
10561059
}

0 commit comments

Comments
 (0)