validation: redundant access mode, fix error msg and add unittest

Bug: tint:1070
Change-Id: Ibc6fb02abf891f57874494ddb8dcac0b4480f990
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60140
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Sarah 2021-07-28 09:59:35 +00:00 committed by Tint LUCI CQ
parent edecbb161f
commit 085dcbbe20
2 changed files with 14 additions and 2 deletions

View File

@ -979,8 +979,8 @@ bool Resolver::ValidateGlobalVariable(const VariableInfo* info) {
if (info->storage_class != ast::StorageClass::kStorage && if (info->storage_class != ast::StorageClass::kStorage &&
info->declaration->declared_access() != ast::Access::kUndefined) { info->declaration->declared_access() != ast::Access::kUndefined) {
AddError( AddError(
"variables declared not declared in the <storage> storage class must " "variables not in <storage> storage class must not declare an access "
"not declare an access control", "mode",
info->declaration->source()); info->declaration->source());
return false; return false;
} }

View File

@ -99,6 +99,18 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferBoolAlias) {
R"(56:78 error: variables declared in the <storage> storage class must be of a structure type)"); R"(56:78 error: variables declared in the <storage> storage class must be of a structure type)");
} }
TEST_F(ResolverStorageClassValidationTest, NotStorage_AccessMode) {
// var<private, read> g : a;
Global(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kPrivate,
ast::Access::kRead);
ASSERT_FALSE(r()->Resolve());
EXPECT_EQ(
r()->error(),
R"(56:78 error: variables not in <storage> storage class must not declare an access mode)");
}
TEST_F(ResolverStorageClassValidationTest, StorageBufferNoBlockDecoration) { TEST_F(ResolverStorageClassValidationTest, StorageBufferNoBlockDecoration) {
// struct S { x : i32 }; // struct S { x : i32 };
// var<storage, read> g : S; // var<storage, read> g : S;