resolver: Check IsStorable() earlier for array els

This was done in ValidateArray(), but this comes after the call to DefaultAlignAndSize(), which will ICE if the type is not storable.

Change-Id: Ia3f1b640f42a45362487c3156237b59ea6fed68b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53043
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-06-03 08:24:55 +00:00 committed by Tint LUCI CQ
parent 0e66b403a0
commit efb741fe13
2 changed files with 19 additions and 8 deletions

View File

@ -2653,6 +2653,14 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
return nullptr;
}
if (!IsStorable(el_ty)) { // Check must come before DefaultAlignAndSize()
builder_->Diagnostics().add_error(
el_ty->FriendlyName(builder_->Symbols()) +
" cannot be used as an element type of an array",
source);
return nullptr;
}
uint32_t el_align = 0;
uint32_t el_size = 0;
if (!DefaultAlignAndSize(el_ty, el_align, el_size)) {
@ -2702,14 +2710,6 @@ sem::Array* Resolver::Array(const ast::Array* arr) {
bool Resolver::ValidateArray(const sem::Array* arr, const Source& source) {
auto* el_ty = arr->ElemType();
if (!IsStorable(el_ty)) {
builder_->Diagnostics().add_error(
el_ty->FriendlyName(builder_->Symbols()) +
" cannot be used as an element type of an array",
source);
return false;
}
if (auto* el_str = el_ty->As<sem::Struct>()) {
if (el_str->IsBlockDecorated()) {
// https://gpuweb.github.io/gpuweb/wgsl/#attributes

View File

@ -353,6 +353,17 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
EXPECT_TRUE(r()->Resolve()) << r()->error();
}
TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) {
auto* tex_ty = ty.sampled_texture(ast::TextureDimension::k2d, ty.f32());
Global("arr", ty.array(Source{{12, 34}}, tex_ty, 4),
ast::StorageClass::kPrivate);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: texture_2d<f32> cannot be used as an element type of "
"an array");
}
namespace GetCanonicalTests {
struct Params {
create_ast_type_func_ptr create_ast_type;