Resolver: apply type storage class uses via parameters

Bug: tint:185
Bug: tint:682
Change-Id: I0a35d9419af3a74376ef96197bbe99630d54632e
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46381
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton 2021-03-30 20:06:48 +00:00 committed by Commit Bot service account
parent ced00a2380
commit 59b28c4cbc
2 changed files with 22 additions and 0 deletions

View File

@ -248,6 +248,15 @@ bool Resolver::ValidateFunction(const ast::Function* func) {
}
for (auto* param : func->params()) {
if (!ApplyStorageClassUsageToType(param->declared_storage_class(),
param->declared_type(),
param->source())) {
diagnostics_.add_note("while instantiating parameter " +
builder_->Symbols().NameFor(param->symbol()),
param->source());
return false;
}
if (!ValidateParameter(param)) {
return false;
}

View File

@ -36,6 +36,19 @@ TEST_F(ResolverStorageClassUseTest, UnreachableStruct) {
EXPECT_TRUE(sem->StorageClassUsage().empty());
}
TEST_F(ResolverStorageClassUseTest, StructReachableFromParameter) {
auto* s = Structure("S", {Member("a", ty.f32())});
Func("f", {Var("param", s, ast::StorageClass::kNone)}, ty.void_(), {}, {});
ASSERT_TRUE(r()->Resolve()) << r()->error();
auto* sem = Sem().Get(s);
ASSERT_NE(sem, nullptr);
EXPECT_THAT(sem->StorageClassUsage(),
UnorderedElementsAre(ast::StorageClass::kNone));
}
TEST_F(ResolverStorageClassUseTest, StructReachableFromGlobal) {
auto* s = Structure("S", {Member("a", ty.f32())});