diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 8c95457f20..48b35fa190 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -2920,9 +2920,14 @@ bool Resolver::ArrayAttributes(utils::VectorRef attribute for (auto* attr : attributes) { Mark(attr); if (auto* sd = attr->As()) { - explicit_stride = sd->stride; - if (!validator_.ArrayStrideAttribute(sd, el_ty->Size(), el_ty->Align())) { - return false; + // If the element type is not plain, then el_ty->Align() may be 0, in which case we + // could get a DBZ in ArrayStrideAttribute(). In this case, validation will error about + // the invalid array element type (which is tested later), so this is just a seatbelt. + if (IsPlain(el_ty)) { + explicit_stride = sd->stride; + if (!validator_.ArrayStrideAttribute(sd, el_ty->Size(), el_ty->Align())) { + return false; + } } continue; } diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc index b539e494e3..59367d0a9e 100644 --- a/src/tint/resolver/type_validation_test.cc +++ b/src/tint/resolver/type_validation_test.cc @@ -836,6 +836,15 @@ TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) { "12:34 error: texture_2d cannot be used as an element type of an array"); } +TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableTypeWithStride) { + auto* ptr_ty = ty.pointer(Source{{12, 34}}, ast::AddressSpace::kUniform); + GlobalVar("arr", ty.array(ptr_ty, 4_i, 16), ast::AddressSpace::kPrivate); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "12:34 error: ptr cannot be used as an element type of an array"); +} + TEST_F(ResolverTypeValidationTest, VariableAsType) { // var a : i32; // var b : a;