[resolver] Apply type storage class uses via return types

Change-Id: I16cf23af7f6a792d22268e6af45c77d4faeb6918
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/46460
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-03-31 15:44:07 +00:00 committed by Commit Bot service account
parent 494e82dc8a
commit 5c523f331d
2 changed files with 21 additions and 0 deletions

View File

@ -321,6 +321,14 @@ bool Resolver::Function(ast::Function* func) {
if (auto* str =
func->return_type()->UnwrapAliasIfNeeded()->As<type::Struct>()) {
if (!ApplyStorageClassUsageToType(ast::StorageClass::kNone, str,
func->source())) {
diagnostics_.add_note("while instantiating return type for " +
builder_->Symbols().NameFor(func->symbol()),
func->source());
return false;
}
auto* info = Structure(str);
if (!info) {
return false;

View File

@ -49,6 +49,19 @@ TEST_F(ResolverStorageClassUseTest, StructReachableFromParameter) {
UnorderedElementsAre(ast::StorageClass::kNone));
}
TEST_F(ResolverStorageClassUseTest, StructReachableFromReturnType) {
auto* s = Structure("S", {Member("a", ty.f32())});
Func("f", {}, s, {Return(Construct(s))}, {});
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())});