diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 6a99791600..b0a32f67e1 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -1128,6 +1128,64 @@ uint32_t Builder::GenerateConstructorExpression( return 0; } +bool Builder::is_constructor_const(ast::Expression* expr, bool is_global_init) { + if (!expr->IsConstructor()) { + return false; + } + if (expr->AsConstructor()->IsScalarConstructor()) { + return true; + } + + auto* tc = expr->AsConstructor()->AsTypeConstructor(); + auto* result_type = tc->type()->UnwrapAliasPtrAlias(); + for (size_t i = 0; i < tc->values().size(); ++i) { + auto* e = tc->values()[i].get(); + + if (!e->IsConstructor()) { + if (is_global_init) { + error_ = "constructor must be a constant expression"; + return false; + } + return false; + } + if (!is_constructor_const(e, is_global_init)) { + return false; + } + if (has_error()) { + return false; + } + + if (result_type->IsVector() && !e->AsConstructor()->IsScalarConstructor()) { + return false; + } + + // This should all be handled by |is_constructor_const| call above + if (!e->AsConstructor()->IsScalarConstructor()) { + continue; + } + + auto* sc = e->AsConstructor()->AsScalarConstructor(); + ast::type::Type* subtype = result_type->UnwrapAliasPtrAlias(); + if (subtype->IsVector()) { + subtype = subtype->AsVector()->type()->UnwrapAliasPtrAlias(); + } else if (subtype->IsMatrix()) { + subtype = subtype->AsMatrix()->type()->UnwrapAliasPtrAlias(); + } else if (subtype->IsArray()) { + subtype = subtype->AsArray()->type()->UnwrapAliasPtrAlias(); + } else if (subtype->IsStruct()) { + subtype = subtype->AsStruct() + ->impl() + ->members()[i] + ->type() + ->UnwrapAliasPtrAlias(); + } + if (subtype != sc->result_type()->UnwrapAliasPtrAlias()) { + return false; + } + } + return true; +} + uint32_t Builder::GenerateTypeConstructorExpression( ast::TypeConstructorExpression* init, bool is_global_init) { @@ -1143,30 +1201,13 @@ uint32_t Builder::GenerateTypeConstructorExpression( out << "__const"; auto* result_type = init->type()->UnwrapAliasPtrAlias(); - - OperandList ops; - bool constructor_is_const = true; - for (const auto& e : values) { - if (!e->IsConstructor()) { - if (is_global_init) { - error_ = "constructor must be a constant expression"; - return 0; - } - constructor_is_const = false; - break; - } else if (result_type->IsVector()) { - // Even if we have constructor parameters if the types are different then - // the constructor is not const as we'll generate OpBitcast or - // OpCopyObject instructions. - auto* subtype = result_type->AsVector()->type()->UnwrapAliasPtrAlias(); - if (subtype != e->result_type()->UnwrapAliasPtrAlias()) { - constructor_is_const = false; - break; - } - } + bool constructor_is_const = is_constructor_const(init, is_global_init); + if (has_error()) { + return 0; } bool can_cast_or_copy = result_type->is_scalar(); + if (result_type->IsVector() && result_type->AsVector()->type()->is_scalar()) { auto* value_type = values[0]->result_type()->UnwrapAliasPtrAlias(); can_cast_or_copy = @@ -1190,6 +1231,7 @@ uint32_t Builder::GenerateTypeConstructorExpression( result_type = result_type->AsVector()->type(); } + OperandList ops; for (const auto& e : values) { uint32_t id = 0; if (constructor_is_const) { diff --git a/src/writer/spirv/builder.h b/src/writer/spirv/builder.h index cc8cc9dc55..29b5711df8 100644 --- a/src/writer/spirv/builder.h +++ b/src/writer/spirv/builder.h @@ -437,6 +437,12 @@ class Builder { SpvImageFormat convert_image_format_to_spv( const ast::type::ImageFormat format); + /// Determines if the given type constructor is created from constant values + /// @param expr the expression to check + /// @param is_global_init if this is a global initializer + /// @returns true if the constructor is constant + bool is_constructor_const(ast::Expression* expr, bool is_global_init); + private: /// @returns an Operand with a new result ID in it. Increments the next_id_ /// automatically. diff --git a/src/writer/spirv/builder_assign_test.cc b/src/writer/spirv/builder_assign_test.cc index ef36625280..2d532426e4 100644 --- a/src/writer/spirv/builder_assign_test.cc +++ b/src/writer/spirv/builder_assign_test.cc @@ -178,7 +178,6 @@ OpStore %1 %13 TEST_F(BuilderTest, Assign_Var_Complex_Constructor) { ast::type::F32Type f32; ast::type::VectorType vec3(&f32, 3); - ast::type::VectorType vec(&vec3, 3); ast::ExpressionList vals; vals.push_back(std::make_unique( @@ -187,35 +186,11 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) { std::make_unique(&f32, 2.0f))); vals.push_back(std::make_unique( std::make_unique(&f32, 3.0f))); - auto first = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::make_unique( - std::make_unique(&f32, 3.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 2.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); - auto second = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::make_unique( - std::make_unique(&f32, 2.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 3.0f))); - auto third = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::move(first)); - vals.push_back(std::move(second)); - vals.push_back(std::move(third)); auto init = - std::make_unique(&vec, std::move(vals)); + std::make_unique(&vec3, std::move(vals)); - ast::Variable v("var", ast::StorageClass::kOutput, &vec); + ast::Variable v("var", ast::StorageClass::kOutput, &vec3); ast::AssignmentStatement assign( std::make_unique("var"), std::move(init)); @@ -234,21 +209,17 @@ TEST_F(BuilderTest, Assign_Var_Complex_Constructor) { EXPECT_TRUE(b.GenerateAssignStatement(&assign)) << b.error(); EXPECT_FALSE(b.has_error()); - EXPECT_EQ(DumpInstructions(b.types()), R"(%5 = OpTypeFloat 32 -%4 = OpTypeVector %5 3 + EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeFloat 32 %3 = OpTypeVector %4 3 %2 = OpTypePointer Output %3 -%6 = OpConstantNull %3 -%1 = OpVariable %2 Output %6 -%7 = OpConstant %5 1 -%8 = OpConstant %5 2 -%9 = OpConstant %5 3 -%10 = OpConstantComposite %4 %7 %8 %9 -%11 = OpConstantComposite %4 %9 %8 %7 -%12 = OpConstantComposite %4 %8 %7 %9 -%13 = OpConstantComposite %3 %10 %11 %12 +%5 = OpConstantNull %3 +%1 = OpVariable %2 Output %5 +%6 = OpConstant %4 1 +%7 = OpConstant %4 2 +%8 = OpConstant %4 3 +%9 = OpConstantComposite %3 %6 %7 %8 )"); - EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %1 %13 + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), R"(OpStore %1 %9 )"); } diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 26240864c6..35e8730e85 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -95,6 +95,49 @@ TEST_F(BuilderTest, Constructor_Type) { )"); } +TEST_F(BuilderTest, Constructor_Type_WithCasts) { + ast::type::F32Type f32; + ast::type::I32Type i32; + ast::type::VectorType vec(&f32, 2); + + ast::ExpressionList type_vals; + type_vals.push_back(std::make_unique( + std::make_unique(&i32, 1))); + + ast::ExpressionList vals; + vals.push_back(std::make_unique( + &f32, std::move(type_vals))); + + type_vals.push_back(std::make_unique( + std::make_unique(&i32, 1))); + vals.push_back(std::make_unique( + &f32, std::move(type_vals))); + + ast::TypeConstructorExpression t(&vec, std::move(vals)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + EXPECT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + b.push_function(Function{}); + + EXPECT_EQ(b.GenerateExpression(&t), 7u); + ASSERT_FALSE(b.has_error()) << b.error(); + + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 +%1 = OpTypeVector %2 2 +%4 = OpTypeInt 32 1 +%5 = OpConstant %4 1 +)"); + EXPECT_EQ(DumpInstructions(b.functions()[0].instructions()), + R"(%3 = OpConvertSToF %2 %5 +%6 = OpConvertSToF %2 %5 +%7 = OpCompositeConstruct %1 %3 %6 +)"); +} + TEST_F(BuilderTest, Constructor_Type_WithAlias) { ast::type::I32Type i32; ast::type::F32Type f32; @@ -2384,6 +2427,407 @@ TEST_F(BuilderTest, Constructor_Type_Convert_Vectors_U32_to_F32) { )"); } +TEST_F(BuilderTest, IsConstructorConst_GlobalVectorWithAllConstConstructors) { + // vec3(1.0, 2.0, 3.0) -> true + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + ast::TypeConstructorExpression t(&vec, std::move(params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_TRUE(b.is_constructor_const(&t, true)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_GlobalVector_WithIdent) { + // vec3(a, b, c) -> false -- ERROR + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList params; + params.push_back(std::make_unique("a")); + params.push_back(std::make_unique("b")); + params.push_back(std::make_unique("c")); + ast::TypeConstructorExpression t(&vec, std::move(params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, true)); + EXPECT_TRUE(b.has_error()); + EXPECT_EQ(b.error(), "constructor must be a constant expression"); +} + +TEST_F(BuilderTest, IsConstructorConst_GlobalArrayWithAllConstConstructors) { + // array, 2>(vec3(1.0, 2.0, 3.0), vec3(1.0, 2.0, 3.0)) + // -> true + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + ast::type::ArrayType ary(&vec, 2); + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + auto first = + std::make_unique(&vec, std::move(params)); + + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + auto second = + std::make_unique(&vec, std::move(params)); + + ast::ExpressionList ary_params; + ary_params.push_back(std::move(first)); + ary_params.push_back(std::move(second)); + ast::TypeConstructorExpression t(&ary, std::move(ary_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_TRUE(b.is_constructor_const(&t, true)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, + IsConstructorConst_GlobalVectorWithMatchingTypeConstructors) { + // vec3(f32(1.0), f32(2.0)) -> false + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 2); + + ast::ExpressionList vec_params; + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&f32, 1.0))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + params.push_back(std::make_unique( + std::make_unique(&f32, 2.0))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + ast::TypeConstructorExpression t(&vec, std::move(vec_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, true)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_GlobalWithTypeCastConstructor) { + // vec3(f32(1), f32(2)) -> false + ast::type::F32Type f32; + ast::type::I32Type i32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList vec_params; + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&i32, 1))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + params.push_back(std::make_unique( + std::make_unique(&i32, 2))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + ast::TypeConstructorExpression t(&vec, std::move(vec_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, true)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_VectorWithAllConstConstructors) { + // vec3(1.0, 2.0, 3.0) -> true + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + ast::TypeConstructorExpression t(&vec, std::move(params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_TRUE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_Vector_WithIdent) { + // vec3(a, b, c) -> false + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList params; + params.push_back(std::make_unique("a")); + params.push_back(std::make_unique("b")); + params.push_back(std::make_unique("c")); + ast::TypeConstructorExpression t(&vec, std::move(params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_ArrayWithAllConstConstructors) { + // array, 2>(vec3(1.0, 2.0, 3.0), vec3(1.0, 2.0, 3.0)) + // -> true + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + ast::type::ArrayType ary(&vec, 2); + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + auto first = + std::make_unique(&vec, std::move(params)); + + params.push_back(std::make_unique( + std::make_unique(&f32, 1.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 2.f))); + params.push_back(std::make_unique( + std::make_unique(&f32, 3.f))); + auto second = + std::make_unique(&vec, std::move(params)); + + ast::ExpressionList ary_params; + ary_params.push_back(std::move(first)); + ary_params.push_back(std::move(second)); + ast::TypeConstructorExpression t(&ary, std::move(ary_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_TRUE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_VectorWith_TypeCastConstConstructors) { + // vec2(f32(1.0), f32(2.0)) -> false + ast::type::F32Type f32; + ast::type::I32Type i32; + ast::type::VectorType vec(&f32, 2); + + ast::ExpressionList vec_params; + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&i32, 1))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + params.push_back(std::make_unique( + std::make_unique(&i32, 2))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + ast::TypeConstructorExpression t(&vec, std::move(vec_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_WithTypeCastConstructor) { + // vec3(f32(1), f32(2)) -> false + ast::type::F32Type f32; + ast::type::I32Type i32; + ast::type::VectorType vec(&f32, 3); + + ast::ExpressionList vec_params; + + ast::ExpressionList params; + params.push_back(std::make_unique( + std::make_unique(&i32, 1))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + params.push_back(std::make_unique( + std::make_unique(&i32, 2))); + vec_params.push_back(std::make_unique( + &f32, std::move(params))); + + ast::TypeConstructorExpression t(&vec, std::move(vec_params)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_BitCastScalars) { + ast::type::I32Type i32; + ast::type::U32Type u32; + ast::type::VectorType vec(&u32, 2); + + ast::ExpressionList vals; + vals.push_back(std::make_unique( + std::make_unique(&i32, 1))); + vals.push_back(std::make_unique( + std::make_unique(&i32, 1))); + + ast::TypeConstructorExpression t(&vec, std::move(vals)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_Struct) { + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::StructMemberDecorationList decos; + ast::StructMemberList members; + members.push_back( + std::make_unique("a", &f32, std::move(decos))); + members.push_back( + std::make_unique("b", &vec, std::move(decos))); + + auto s = std::make_unique(std::move(members)); + ast::type::StructType s_type(std::move(s)); + s_type.set_name("my_struct"); + + ast::ExpressionList vec_vals; + vec_vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + vec_vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + vec_vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + + ast::ExpressionList vals; + vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + vals.push_back(std::make_unique( + &vec, std::move(vec_vals))); + + ast::TypeConstructorExpression t(&s_type, std::move(vals)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_TRUE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + +TEST_F(BuilderTest, IsConstructorConst_Struct_WithIdentSubExpression) { + ast::type::F32Type f32; + ast::type::VectorType vec(&f32, 3); + + ast::StructMemberDecorationList decos; + ast::StructMemberList members; + members.push_back( + std::make_unique("a", &f32, std::move(decos))); + members.push_back( + std::make_unique("b", &vec, std::move(decos))); + + auto s = std::make_unique(std::move(members)); + ast::type::StructType s_type(std::move(s)); + s_type.set_name("my_struct"); + + ast::ExpressionList vec_vals; + vec_vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + vec_vals.push_back(std::make_unique("a")); + vec_vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + + ast::ExpressionList vals; + vals.push_back(std::make_unique( + std::make_unique(&f32, 2))); + vals.push_back(std::make_unique( + &vec, std::move(vec_vals))); + + ast::TypeConstructorExpression t(&s_type, std::move(vals)); + + Context ctx; + ast::Module mod; + TypeDeterminer td(&ctx, &mod); + ASSERT_TRUE(td.DetermineResultType(&t)) << td.error(); + + Builder b(&mod); + EXPECT_FALSE(b.is_constructor_const(&t, false)); + EXPECT_FALSE(b.has_error()); +} + } // namespace } // namespace spirv } // namespace writer diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index a6ebce8569..14106b9b0e 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -176,7 +176,6 @@ TEST_F(BuilderTest, GlobalVar_Const) { TEST_F(BuilderTest, GlobalVar_Complex_Constructor) { ast::type::F32Type f32; ast::type::VectorType vec3(&f32, 3); - ast::type::VectorType vec(&vec3, 3); ast::ExpressionList vals; vals.push_back(std::make_unique( @@ -185,33 +184,8 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) { std::make_unique(&f32, 2.0f))); vals.push_back(std::make_unique( std::make_unique(&f32, 3.0f))); - auto first = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::make_unique( - std::make_unique(&f32, 3.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 2.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); - auto second = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::make_unique( - std::make_unique(&f32, 2.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 1.0f))); - vals.push_back(std::make_unique( - std::make_unique(&f32, 3.0f))); - auto third = - std::make_unique(&vec3, std::move(vals)); - - vals.push_back(std::move(first)); - vals.push_back(std::move(second)); - vals.push_back(std::move(third)); - auto init = - std::make_unique(&vec, std::move(vals)); + std::make_unique(&vec3, std::move(vals)); Context ctx; ast::Module mod; @@ -227,16 +201,12 @@ TEST_F(BuilderTest, GlobalVar_Complex_Constructor) { EXPECT_TRUE(b.GenerateGlobalVariable(&v)) << b.error(); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), R"(%3 = OpTypeFloat 32 -%2 = OpTypeVector %3 3 + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeVector %2 3 -%4 = OpConstant %3 1 -%5 = OpConstant %3 2 -%6 = OpConstant %3 3 -%7 = OpConstantComposite %2 %4 %5 %6 -%8 = OpConstantComposite %2 %6 %5 %4 -%9 = OpConstantComposite %2 %5 %4 %6 -%10 = OpConstantComposite %1 %7 %8 %9 +%3 = OpConstant %2 1 +%4 = OpConstant %2 2 +%5 = OpConstant %2 3 +%6 = OpConstantComposite %1 %3 %4 %5 )"); }