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 <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2022-11-17 19:59:19 +00:00 committed by Dawn LUCI CQ
parent 7bae191936
commit c2e2013c2d
2 changed files with 17 additions and 3 deletions

View File

@ -2920,9 +2920,14 @@ bool Resolver::ArrayAttributes(utils::VectorRef<const ast::Attribute*> attribute
for (auto* attr : attributes) { for (auto* attr : attributes) {
Mark(attr); Mark(attr);
if (auto* sd = attr->As<ast::StrideAttribute>()) { if (auto* sd = attr->As<ast::StrideAttribute>()) {
explicit_stride = sd->stride; // If the element type is not plain, then el_ty->Align() may be 0, in which case we
if (!validator_.ArrayStrideAttribute(sd, el_ty->Size(), el_ty->Align())) { // could get a DBZ in ArrayStrideAttribute(). In this case, validation will error about
return false; // 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; continue;
} }

View File

@ -836,6 +836,15 @@ TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) {
"12:34 error: texture_2d<f32> cannot be used as an element type of an array"); "12:34 error: texture_2d<f32> cannot be used as an element type of an array");
} }
TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableTypeWithStride) {
auto* ptr_ty = ty.pointer<u32>(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<uniform, u32, read> cannot be used as an element type of an array");
}
TEST_F(ResolverTypeValidationTest, VariableAsType) { TEST_F(ResolverTypeValidationTest, VariableAsType) {
// var<private> a : i32; // var<private> a : i32;
// var<private> b : a; // var<private> b : a;