validation: structures cannot be empty

Fixed many tests that had empty structures.

Change-Id: Id91312afa39a6293426f99d0dd12578dba46aa61
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56621
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-07-01 08:13:41 +00:00 committed by Tint LUCI CQ
parent d4c64af117
commit 37cabbb468
42 changed files with 86 additions and 36 deletions

View File

@ -359,7 +359,7 @@ using StructDecorationTest = TestWithParams;
TEST_P(StructDecorationTest, IsValid) {
auto& params = GetParam();
Structure("mystruct", {},
Structure("mystruct", {Member("a", ty.f32())},
createDecorations(Source{{12, 34}}, *this, params.kind));
WrapInFunction();

View File

@ -102,12 +102,13 @@ TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Multiple) {
TEST_F(ResolverEntryPointValidationTest, ReturnTypeAttribute_Struct) {
// struct Output {
// a : f32;
// };
// [[stage(vertex)]]
// fn main() -> [[location(0)]] Output {
// return Output();
// }
auto* output = Structure("Output", {});
auto* output = Structure("Output", {Member("a", ty.f32())});
Func(Source{{12, 34}}, "main", {}, ty.Of(output),
{Return(Construct(ty.Of(output)))}, {Stage(ast::PipelineStage::kVertex)},
{Location(Source{{13, 43}}, 0)});
@ -328,10 +329,11 @@ TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Multiple) {
TEST_F(ResolverEntryPointValidationTest, ParameterAttribute_Struct) {
// struct Input {
// a : f32;
// };
// [[stage(fragment)]]
// fn main([[location(0)]] param : Input) {}
auto* input = Structure("Input", {});
auto* input = Structure("Input", {Member("a", ty.f32())});
auto* param = Param("param", ty.Of(input), {Location(Source{{13, 43}}, 0)});
Func(Source{{12, 34}}, "main", {param}, ty.void_(), {},
{Stage(ast::PipelineStage::kFragment)});

View File

@ -3360,6 +3360,12 @@ bool Resolver::ValidateArrayStrideDecoration(const ast::StrideDecoration* deco,
}
bool Resolver::ValidateStructure(const sem::Struct* str) {
if (str->Members().empty()) {
AddError("structures must have at least one member",
str->Declaration()->source());
return false;
}
for (auto* member : str->Members()) {
if (auto* r = member->Type()->As<sem::Array>()) {
if (r->IsRuntimeSized()) {

View File

@ -28,6 +28,7 @@ TEST_F(BindingRemapperTest, NoRemappings) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, read> a : S;
@ -53,6 +54,7 @@ TEST_F(BindingRemapperTest, RemapBindingPoints) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, read> a : S;
@ -67,6 +69,7 @@ fn f() {
auto* expect = R"(
[[block]]
struct S {
a : f32;
};
[[group(1), binding(2)]] var<storage, read> a : S;
@ -95,6 +98,7 @@ TEST_F(BindingRemapperTest, RemapAccessControls) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, read> a : S;
@ -111,6 +115,7 @@ fn f() {
auto* expect = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, write> a : S;
@ -143,6 +148,7 @@ TEST_F(BindingRemapperTest, DISABLED_RemapAccessControlsWithAliases) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
type, read ReadOnlyS = S;
@ -165,6 +171,7 @@ fn f() {
auto* expect = R"(
[[block]]
struct S {
a : f32;
};
type, read ReadOnlyS = S;
@ -201,6 +208,7 @@ TEST_F(BindingRemapperTest, RemapAll) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, read> a : S;
@ -215,6 +223,7 @@ fn f() {
auto* expect = R"(
[[block]]
struct S {
a : f32;
};
[[group(4), binding(5)]] var<storage, write> a : S;
@ -363,6 +372,7 @@ TEST_F(BindingRemapperTest, NoData) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(2), binding(1)]] var<storage, read> a : S;

View File

@ -191,6 +191,7 @@ TEST_F(MslTest, HandleModuleScopeVariables_OtherVariables) {
auto* src = R"(
[[block]]
struct S {
a : f32;
};
[[group(0), binding(0)]]
@ -204,6 +205,7 @@ fn main() {
auto* expect = R"(
[[block]]
struct S {
a : f32;
};
[[group(0), binding(0)]] var<uniform> u : S;

View File

@ -169,7 +169,11 @@ TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct) {
}
TEST_F(MslGeneratorImplTest, EmitConstructor_Type_Struct_Empty) {
auto* str = Structure("S", {});
auto* str = Structure("S", {
Member("a", ty.i32()),
Member("b", ty.f32()),
Member("c", ty.vec3<i32>()),
});
WrapInFunction(Construct(ty.Of(str)));

View File

@ -266,22 +266,6 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedPtr) {
EXPECT_EQ(b.GenerateTypeIfNeeded(ptr), 1u);
}
TEST_F(BuilderTest_Type, GenerateStruct_Empty) {
auto* s = Structure("S", {});
spirv::Builder& b = Build();
auto id = b.GenerateTypeIfNeeded(program->TypeOf(s));
ASSERT_FALSE(b.has_error()) << b.error();
EXPECT_EQ(id, 1u);
EXPECT_EQ(b.types().size(), 1u);
EXPECT_EQ(DumpInstructions(b.debug()), R"(OpName %1 "S"
)");
EXPECT_EQ(DumpInstructions(b.types()), R"(%1 = OpTypeStruct
)");
}
TEST_F(BuilderTest_Type, GenerateStruct) {
auto* s = Structure("my_struct", {Member("a", ty.f32())});

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
[[stage(compute), workgroup_size(1)]]

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];
@ -24,7 +25,7 @@ void main() {
const float3x4 m3x4_let = float3x4(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
tint_array_wrapper arr_var = {{0.0f, 0.0f, 0.0f, 0.0f}};
const tint_array_wrapper arr_let = {{0.0f, 0.0f, 0.0f, 0.0f}};
S struct_var = {};
const S struct_let = {};
S struct_var = {0.0f};
const S struct_let = {0.0f};
return;
}

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -18,8 +18,10 @@
OpName %m2x3_var "m2x3_var"
OpName %arr_var "arr_var"
OpName %S "S"
OpMemberName %S 0 "a"
OpName %struct_var "struct_var"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%void = OpTypeVoid
%1 = OpTypeFunction %void
%bool = OpTypeBool
@ -53,7 +55,7 @@
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%42 = OpConstantNull %_arr_float_uint_4
%_ptr_Function__arr_float_uint_4 = OpTypePointer Function %_arr_float_uint_4
%S = OpTypeStruct
%S = OpTypeStruct %float
%46 = OpConstantNull %S
%_ptr_Function_S = OpTypePointer Function %S
%main = OpFunction %void None %1

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
[[stage(compute), workgroup_size(1)]]

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
let bool_let : bool = bool();

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
static const bool bool_let = false;
@ -15,7 +16,7 @@ struct tint_array_wrapper {
};
static const tint_array_wrapper arr_let = {{0.0f, 0.0f, 0.0f, 0.0f}};
static const S struct_let = {};
static const S struct_let = {0.0f};
[numthreads(1, 1, 1)]
void main() {

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -17,9 +17,11 @@
OpName %m3x4_let "m3x4_let"
OpName %arr_let "arr_let"
OpName %S "S"
OpMemberName %S 0 "a"
OpName %struct_let "struct_let"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%bool = OpTypeBool
%bool_let = OpConstantNull %bool
%int = OpTypeInt 32 1
@ -39,7 +41,7 @@
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%arr_let = OpConstantNull %_arr_float_uint_4
%S = OpTypeStruct
%S = OpTypeStruct %float
%struct_let = OpConstantNull %S
%void = OpTypeVoid
%22 = OpTypeFunction %void

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
let bool_let : bool = bool();

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
var<private> bool_var : bool;

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
static bool bool_var = false;
@ -15,7 +16,7 @@ struct tint_array_wrapper {
};
static tint_array_wrapper arr_var = {{0.0f, 0.0f, 0.0f, 0.0f}};
static S struct_var = {};
static S struct_var = {0.0f};
[numthreads(1, 1, 1)]
void main() {
@ -29,7 +30,7 @@ void main() {
m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
const tint_array_wrapper tint_symbol = {{0.0f, 0.0f, 0.0f, 0.0f}};
arr_var = tint_symbol;
const S tint_symbol_1 = {};
const S tint_symbol_1 = {0.0f};
struct_var = tint_symbol_1;
return;
}

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -17,9 +17,11 @@
OpName %m2x3_var "m2x3_var"
OpName %arr_var "arr_var"
OpName %S "S"
OpMemberName %S 0 "a"
OpName %struct_var "struct_var"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%bool = OpTypeBool
%_ptr_Private_bool = OpTypePointer Private %bool
%4 = OpConstantNull %bool
@ -58,7 +60,7 @@
%_ptr_Private__arr_float_uint_4 = OpTypePointer Private %_arr_float_uint_4
%38 = OpConstantNull %_arr_float_uint_4
%arr_var = OpVariable %_ptr_Private__arr_float_uint_4 Private %38
%S = OpTypeStruct
%S = OpTypeStruct %float
%_ptr_Private_S = OpTypePointer Private %S
%42 = OpConstantNull %S
%struct_var = OpVariable %_ptr_Private_S Private %42

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
var<private> bool_var : bool;

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
var<private> bool_var : bool = bool();

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
static bool bool_var = false;
@ -15,7 +16,7 @@ struct tint_array_wrapper {
};
static tint_array_wrapper arr_var = {{0.0f, 0.0f, 0.0f, 0.0f}};
static S struct_var = {};
static S struct_var = {0.0f};
[numthreads(1, 1, 1)]
void main() {
@ -29,7 +30,7 @@ void main() {
m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
const tint_array_wrapper tint_symbol = {{0.0f, 0.0f, 0.0f, 0.0f}};
arr_var = tint_symbol;
const S tint_symbol_1 = {};
const S tint_symbol_1 = {0.0f};
struct_var = tint_symbol_1;
return;
}

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -17,9 +17,11 @@
OpName %m2x3_var "m2x3_var"
OpName %arr_var "arr_var"
OpName %S "S"
OpMemberName %S 0 "a"
OpName %struct_var "struct_var"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%bool = OpTypeBool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
@ -58,7 +60,7 @@
%36 = OpConstantNull %_arr_float_uint_4
%_ptr_Private__arr_float_uint_4 = OpTypePointer Private %_arr_float_uint_4
%arr_var = OpVariable %_ptr_Private__arr_float_uint_4 Private %36
%S = OpTypeStruct
%S = OpTypeStruct %float
%40 = OpConstantNull %S
%_ptr_Private_S = OpTypePointer Private %S
%struct_var = OpVariable %_ptr_Private_S Private %40

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
var<private> bool_var : bool = bool();

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
fn foo(

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -8,6 +8,7 @@
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %S "S"
OpMemberName %S 0 "a"
OpName %foo "foo"
OpName %param_bool "param_bool"
OpName %param_i32 "param_i32"
@ -24,6 +25,7 @@
OpName %param_ptr_arr "param_ptr_arr"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%void = OpTypeVoid
%bool = OpTypeBool
%int = OpTypeInt 32 1
@ -36,7 +38,7 @@
%mat2v3float = OpTypeMatrix %v3float 2
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%S = OpTypeStruct
%S = OpTypeStruct %float
%_ptr_Function_float = OpTypePointer Function %float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Function__arr_float_uint_4 = OpTypePointer Function %_arr_float_uint_4

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
fn foo(param_bool : bool, param_i32 : i32, param_u32 : u32, param_f32 : f32, param_v2i32 : vec2<i32>, param_v3u32 : vec3<u32>, param_v4f32 : vec4<f32>, param_m2x3 : mat2x3<f32>, param_arr : array<f32, 4>, param_struct : S, param_ptr_f32 : ptr<function, f32>, param_ptr_vec : ptr<function, vec4<f32>>, param_ptr_arr : ptr<function, array<f32, 4>>) {

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
fn ret_bool() -> bool { return bool(); }

View File

@ -1,4 +1,5 @@
struct S {
float a;
};
bool ret_bool() {
@ -43,7 +44,7 @@ tint_array_wrapper ret_arr() {
}
S ret_struct() {
const S tint_symbol_1 = {};
const S tint_symbol_1 = {0.0f};
return tint_symbol_1;
}

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -17,9 +17,11 @@
OpName %ret_m2x3 "ret_m2x3"
OpName %ret_arr "ret_arr"
OpName %S "S"
OpMemberName %S 0 "a"
OpName %ret_struct "ret_struct"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 0 Offset 0
%bool = OpTypeBool
%1 = OpTypeFunction %bool
%5 = OpConstantNull %bool
@ -49,7 +51,7 @@
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%42 = OpTypeFunction %_arr_float_uint_4
%47 = OpConstantNull %_arr_float_uint_4
%S = OpTypeStruct
%S = OpTypeStruct %float
%48 = OpTypeFunction %S
%52 = OpConstantNull %S
%void = OpTypeVoid

View File

@ -1,4 +1,5 @@
struct S {
a : f32;
};
fn ret_bool() -> bool {

View File

@ -1,4 +1,5 @@
struct S_inner {
a : f32;
};
struct S {

View File

@ -1,4 +1,5 @@
struct S_inner {
float a;
};
struct tint_array_wrapper {
float arr[4];
@ -18,6 +19,6 @@ struct S {
[numthreads(1, 1, 1)]
void main() {
const S s = {false, 0, 0u, 0.0f, int2(0, 0), uint3(0u, 0u, 0u), float4(0.0f, 0.0f, 0.0f, 0.0f), float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), {{0.0f, 0.0f, 0.0f, 0.0f}}, {}};
const S s = {false, 0, 0u, 0.0f, int2(0, 0), uint3(0u, 0u, 0u), float4(0.0f, 0.0f, 0.0f, 0.0f), float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f), {{0.0f, 0.0f, 0.0f, 0.0f}}, {0.0f}};
return;
}

View File

@ -2,6 +2,7 @@
using namespace metal;
struct S_inner {
float a;
};
struct tint_array_wrapper {
float arr[4];

View File

@ -20,6 +20,7 @@
OpMemberName %S 8 "member_arr"
OpMemberName %S 9 "member_struct"
OpName %S_inner "S_inner"
OpMemberName %S_inner 0 "a"
OpMemberDecorate %S 0 Offset 0
OpMemberDecorate %S 1 Offset 4
OpMemberDecorate %S 2 Offset 8
@ -33,6 +34,7 @@
OpMemberDecorate %S 8 Offset 96
OpDecorate %_arr_float_uint_4 ArrayStride 4
OpMemberDecorate %S 9 Offset 112
OpMemberDecorate %S_inner 0 Offset 0
%void = OpTypeVoid
%1 = OpTypeFunction %void
%bool = OpTypeBool
@ -46,7 +48,7 @@
%mat2v3float = OpTypeMatrix %v3float 2
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%S_inner = OpTypeStruct
%S_inner = OpTypeStruct %float
%S = OpTypeStruct %bool %int %uint %float %v2int %v3uint %v4float %mat2v3float %_arr_float_uint_4 %S_inner
%18 = OpConstantNull %S
%main = OpFunction %void None %1

View File

@ -1,4 +1,5 @@
struct S_inner {
a : f32;
};
struct S {