From 293d313bbca271f9475d75f0eeeed316aeafa17e Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 27 Aug 2021 18:07:38 +0000 Subject: [PATCH] spirv-reader: reject empty structure types SPIR-V supports them but WGSL does not. Fixed: chromium:1230976 Change-Id: I27dbbf4a0f584bcff7355bf513bbd2b924dc349b Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/62922 Auto-Submit: David Neto Kokoro: Kokoro Reviewed-by: James Price Commit-Queue: James Price --- src/reader/spirv/parser_impl.cc | 5 +++++ src/reader/spirv/parser_impl_convert_type_test.cc | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 43886bda1c..bec3e4aeed 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -1089,6 +1089,11 @@ const Type* ParserImpl::ConvertType( // Compute members ast::StructMemberList ast_members; const auto members = struct_ty->element_types(); + if (members.empty()) { + Fail() << "WGSL does not support empty structures. can't convert type: " + << def_use_mgr_->GetDef(type_id)->PrettyPrint(); + return nullptr; + } TypeList ast_member_types; unsigned num_non_writable_members = 0; for (uint32_t member_index = 0; member_index < members.size(); diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index acf2048671..6757647e3f 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -568,6 +568,19 @@ TEST_F(SpvParserTest, ConvertType_ArrayStride_SpecifiedTwiceIsError) { Eq("invalid array type ID 10: multiple ArrayStride decorations")); } +TEST_F(SpvParserTest, ConvertType_StructEmpty) { + auto p = parser(test::Assemble(Preamble() + R"( + %10 = OpTypeStruct + )" + MainBody())); + EXPECT_TRUE(p->BuildInternalModule()); + + auto* type = p->ConvertType(10); + EXPECT_EQ(type, nullptr); + EXPECT_EQ(p->error(), + "WGSL does not support empty structures. can't convert type: %10 = " + "OpTypeStruct"); +} + TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { auto p = parser(test::Assemble(Preamble() + R"( %uint = OpTypeInt 32 0