validation: function scope variable store type must be constructible

- function scope variable store type must be constructible
- add IsConstructible() to sem::atomic

Bug: tint:1069
Change-Id: Ib0616b486ecf278dbdd99640dc4ede7f3007feb8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60120
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
Auto-Submit: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
Sarah
2021-07-28 22:43:36 +00:00
committed by Tint LUCI CQ
parent 9ba6500c3f
commit 7249404827
7 changed files with 63 additions and 26 deletions

View File

@@ -34,7 +34,8 @@ TEST_F(ResolverAtomicValidationTest, GlobalOfInvalidType) {
EXPECT_EQ(r()->error(), "12:34 error: atomic only supports i32 or u32 types");
}
TEST_F(ResolverAtomicValidationTest, GlobalOfInvalidStorageClass) {
// TODO(crbug.com/tint/909): add validation and enable this test
TEST_F(ResolverAtomicValidationTest, DISABLED_GlobalOfInvalidStorageClass) {
Global("a", ty.atomic(Source{{12, 34}}, ty.i32()),
ast::StorageClass::kPrivate);
@@ -60,7 +61,8 @@ TEST_F(ResolverAtomicValidationTest, Local) {
WrapInFunction(Var("a", ty.atomic(Source{{12, 34}}, ty.i32())));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "12:34 error: atomic var requires workgroup storage");
EXPECT_EQ(r()->error(),
"12:34 error: function variable must have a constructible type");
}
TEST_F(ResolverAtomicValidationTest, NoAtomicExpr) {

View File

@@ -1122,19 +1122,6 @@ bool Resolver::ValidateVariable(const VariableInfo* info) {
AddError("invalid use of input/output storage class", var->source());
return false;
}
// https://gpuweb.github.io/gpuweb/wgsl/#atomic-types
// Atomic types may only be instantiated by variables in the workgroup storage
// class or by storage buffer variables with a read_write access mode.
if (info->type->UnwrapRef()->Is<sem::Atomic>() &&
info->storage_class != ast::StorageClass::kWorkgroup) {
// Storage buffers require a structure, so just check for workgroup
// storage here.
AddError("atomic var requires workgroup storage",
info->declaration->type()->source());
return false;
}
return true;
}
@@ -3370,10 +3357,15 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {
return false;
}
if (!var->is_const()) {
if (info->storage_class != ast::StorageClass::kFunction &&
IsValidationEnabled(var->decorations(),
ast::DisabledValidation::kIgnoreStorageClass)) {
if (!var->is_const() &&
IsValidationEnabled(var->decorations(),
ast::DisabledValidation::kIgnoreStorageClass)) {
if (!info->type->UnwrapRef()->IsConstructible()) {
AddError("function variable must have a constructible type",
var->type()->source());
return false;
}
if (info->storage_class != ast::StorageClass::kFunction) {
if (info->storage_class != ast::StorageClass::kNone) {
AddError("function variable has a non-function storage class",
stmt->source());

View File

@@ -352,8 +352,8 @@ TEST_F(ResolverValidationTest, StorageClass_FunctionVariableWorkgroupClass) {
"error: function variable has a non-function storage class");
}
TEST_F(ResolverValidationTest, StorageClass_FunctionVariableHandleClass) {
auto* var = Var("s", ty.sampler(ast::SamplerKind::kSampler));
TEST_F(ResolverValidationTest, StorageClass_FunctionVariableI32) {
auto* var = Var("s", ty.i32(), ast::StorageClass::kPrivate);
auto* stmt = Decl(var);
Func("func", ast::VariableList{}, ty.void_(), ast::StatementList{stmt},

View File

@@ -298,6 +298,35 @@ TEST_F(ResolverVarLetValidationTest, InferredPtrStorageAccessMismatch) {
"'ptr<storage, i32, read>'");
}
TEST_F(ResolverVarLetValidationTest, NonConstructibleType_Atomic) {
auto* v = Var("v", ty.atomic(Source{{12, 34}}, ty.i32()));
WrapInFunction(v);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: function variable must have a constructible type");
}
TEST_F(ResolverVarLetValidationTest, NonConstructibleType_RuntimeArray) {
auto* s = Structure("S", {Member("m", ty.array(ty.i32()))}, {StructBlock()});
auto* v = Var("v", ty.Of(s));
WrapInFunction(v);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"error: function variable must have a constructible type");
}
TEST_F(ResolverVarLetValidationTest, NonConstructibleType_Struct_WithAtomic) {
auto* s = Structure("S", {Member("m", ty.atomic(ty.i32()))});
auto* v = Var("v", ty.Of(s));
WrapInFunction(v);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"error: function variable must have a constructible type");
}
} // namespace
} // namespace resolver
} // namespace tint