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