From 8b2be2d1e2dbfc3c8772a944e7bd23d6c6d9f3e4 Mon Sep 17 00:00:00 2001 From: Antonio Maiorano Date: Fri, 18 Jun 2021 19:57:57 +0000 Subject: [PATCH] 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 Kokoro: Kokoro Commit-Queue: Antonio Maiorano --- src/resolver/decoration_validation_test.cc | 16 ++++++++++++++++ src/resolver/resolver.cc | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/resolver/decoration_validation_test.cc b/src/resolver/decoration_validation_test.cc index 974d1eda4e..d43d8f7f76 100644 --- a/src/resolver/decoration_validation_test.cc +++ b/src/resolver/decoration_validation_test.cc @@ -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(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 diff --git a/src/resolver/resolver.cc b/src/resolver/resolver.cc index 202916aaee..31e9f5db40 100644 --- a/src/resolver/resolver.cc +++ b/src/resolver/resolver.cc @@ -3188,6 +3188,19 @@ bool Resolver::ValidateStructure(const sem::Struct* str) { } } } + + if (auto* member_struct_type = member->Type()->As()) { + if (auto* member_struct_type_block_decoration = + ast::GetDecoration( + 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()) {