Validate that structs must not contain [[block]] decorated struct members

Bug: tint:320
Change-Id: Ia330d194fc343d5cd5dec8fb7a5b126f8f002bc5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/55280
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano 2021-06-18 19:57:57 +00:00 committed by Tint LUCI CQ
parent e6d171ac66
commit 8b2be2d1e2
2 changed files with 29 additions and 0 deletions

View File

@ -617,6 +617,22 @@ TEST_F(StructBlockTest, StructUsedAsArrayElement) {
"used as an element of an array");
}
TEST_F(StructBlockTest, StructWithNestedBlockMember_Invalid) {
auto* inner =
Structure("Inner", {Member("x", ty.i32())},
{create<ast::StructBlockDecoration>(Source{{56, 78}})});
auto* outer =
Structure("Outer", {Member(Source{{12, 34}}, "y", ty.Of(inner))});
Global("G", ty.Of(outer), ast::StorageClass::kPrivate);
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(
r()->error(),
R"(12:34 error: structs must not contain [[block]] decorated struct members
56:78 note: see member's struct decoration here)");
}
} // namespace
} // namespace StructBlockTests

View File

@ -3188,6 +3188,19 @@ bool Resolver::ValidateStructure(const sem::Struct* str) {
}
}
}
if (auto* member_struct_type = member->Type()->As<sem::Struct>()) {
if (auto* member_struct_type_block_decoration =
ast::GetDecoration<ast::StructBlockDecoration>(
member_struct_type->Declaration()->decorations())) {
diagnostics_.add_error(
"structs must not contain [[block]] decorated struct members",
member->Declaration()->source());
diagnostics_.add_note("see member's struct decoration here",
member_struct_type_block_decoration->source());
return false;
}
}
}
for (auto* deco : str->Declaration()->decorations()) {