validation: Reject var<function> at module-scope

Fixed: tint:1368
Change-Id: I15fd0d2cbd9600500213e3140e9ac4500d179eb2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/76160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2022-01-12 20:51:36 +00:00
parent 3e354fd524
commit 13c79bef23
2 changed files with 19 additions and 0 deletions

View File

@ -493,6 +493,14 @@ bool Resolver::ValidateGlobalVariable(const sem::Variable* var) {
}
}
if (var->StorageClass() == ast::StorageClass::kFunction) {
AddError(
"variables declared at module scope must not be in the function "
"storage class",
decl->source);
return false;
}
auto binding_point = decl->BindingPoint();
switch (var->StorageClass()) {
case ast::StorageClass::kUniform:

View File

@ -34,6 +34,17 @@ TEST_F(ResolverStorageClassValidationTest, GlobalVariableNoStorageClass_Fail) {
"12:34 error: global variables must have a storage class");
}
TEST_F(ResolverStorageClassValidationTest,
GlobalVariableFunctionStorageClass_Fail) {
// var<function> g : f32;
Global(Source{{12, 34}}, "g", ty.f32(), ast::StorageClass::kFunction);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: variables declared at module scope must not be in "
"the function storage class");
}
TEST_F(ResolverStorageClassValidationTest, StorageBufferBool) {
// var<storage> g : i32;
Global(Source{{56, 78}}, "g", ty.i32(), ast::StorageClass::kStorage,