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 <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
David Neto 2021-08-27 18:07:38 +00:00 committed by Tint LUCI CQ
parent d30c07e4df
commit 293d313bbc
2 changed files with 18 additions and 0 deletions

View File

@ -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();

View File

@ -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