validation: Allow storage atomics without structs

Fixed: tint:1409
Change-Id: I169fe23ff697e5c997742caba8a37a54867cd3f6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/85526
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2022-04-05 21:01:09 +00:00
parent e6c7fd7110
commit 12f2f9b1bc
2 changed files with 10 additions and 1 deletions

View File

@ -34,6 +34,14 @@ TEST_F(ResolverAtomicValidationTest, StorageClass_WorkGroup) {
}
TEST_F(ResolverAtomicValidationTest, StorageClass_Storage) {
Global("g", ty.atomic(Source{{12, 34}}, ty.i32()),
ast::StorageClass::kStorage, ast::Access::kReadWrite,
GroupAndBinding(0, 0));
EXPECT_TRUE(r()->Resolve()) << r()->error();
}
TEST_F(ResolverAtomicValidationTest, StorageClass_Storage_Struct) {
auto* s =
Structure("s", {Member("a", ty.atomic(Source{{12, 34}}, ty.i32()))});
Global("g", ty.Of(s), ast::StorageClass::kStorage, ast::Access::kReadWrite,

View File

@ -517,7 +517,8 @@ bool Resolver::ValidateAtomicVariable(const sem::Variable* var) {
auto source = decl->type ? decl->type->source : decl->source;
if (type->Is<sem::Atomic>()) {
if (sc != ast::StorageClass::kWorkgroup) {
if (sc != ast::StorageClass::kWorkgroup &&
sc != ast::StorageClass::kStorage) {
AddError(
"atomic variables must have <storage> or <workgroup> storage class",
source);