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>
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index 8c95457..48b35fa 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -2920,9 +2920,14 @@
     for (auto* attr : attributes) {
         Mark(attr);
         if (auto* sd = attr->As<ast::StrideAttribute>()) {
-            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 b539e49..59367d0 100644
--- a/src/tint/resolver/type_validation_test.cc
+++ b/src/tint/resolver/type_validation_test.cc
@@ -836,6 +836,15 @@
               "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) {
     // var<private> a : i32;
     // var<private> b : a;