From c2e2013c2d37d685776e4302bf7827194eca58c6 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 17 Nov 2022 19:59:19 +0000 Subject: [PATCH] tint/resolver: Fix DBZ with explicit strides of invalid arrays Fixed: tint:1693 Change-Id: Ieafc8659daade26c5ce4fab583d3bc03d35c2a2a Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/110580 Commit-Queue: Ben Clayton Auto-Submit: Ben Clayton Reviewed-by: Dan Sinclair Kokoro: Kokoro --- src/tint/resolver/resolver.cc | 11 ++++++++--- src/tint/resolver/type_validation_test.cc | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) 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;