Big cleanup now that AST nodes are raw pointers

Remove all redundant std::move()s. I've also removed calls to
std::move() in tests, even if they act as an optimization. This is for
two reasons:
(a) Performance is not important for testing, and this helps with
    readability.
(b) A whole bunch tests were relying on std::move() clearing vectors so
    they can be repopulated and used again. This is undefined behavior:

> Objects of types defined in the C++ standard library may be moved from
> (12.8). Move operations may be explicitly specified or implicitly
> generated. Unless otherwise specified, such moved-from objects shall
> be placed in a valid but unspecified state.

All of these UB cases have been fixed.

Removed all duplicate variables left over from:
  `auto* foo_ptr = foo.get()`
which became:
  `auto* foo_ptr = foo`

Bug: tint:322
Change-Id: Ibd08a2379671382320fd4d8da296ccc6a378b8af
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/32900
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-11-16 16:41:47 +00:00
committed by Commit Bot service account
parent b053acf796
commit 4bfe461646
130 changed files with 3078 additions and 3708 deletions

View File

@@ -52,12 +52,11 @@ TEST_F(ValidateControlBlockTest, SwitchSelectorExpressionNoneIntegerType_Fail) {
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -80,13 +79,13 @@ TEST_F(ValidateControlBlockTest, SwitchWithoutDefault_Fail) {
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, 1));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(csl),
create<ast::BlockStatement>()));
body.push_back(
create<ast::CaseStatement>(csl, create<ast::BlockStatement>()));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
std::move(cond), std::move(body)));
cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -112,25 +111,23 @@ TEST_F(ValidateControlBlockTest, SwitchWithTwoDefault_Fail) {
ast::CaseSelectorList default_csl_1;
auto* block_default_1 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl_1),
std::move(block_default_1)));
switch_body.push_back(
create<ast::CaseStatement>(default_csl_1, block_default_1));
ast::CaseSelectorList csl_case_1;
csl_case_1.push_back(create<ast::SintLiteral>(&i32, 1));
auto* block_case_1 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(csl_case_1),
std::move(block_case_1)));
switch_body.push_back(create<ast::CaseStatement>(csl_case_1, block_case_1));
ast::CaseSelectorList default_csl_2;
auto* block_default_2 = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl_2),
std::move(block_default_2)));
switch_body.push_back(
create<ast::CaseStatement>(default_csl_2, block_default_2));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(Source{Source::Location{12, 34}},
std::move(cond),
std::move(switch_body)));
cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -158,18 +155,15 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::UintLiteral>(&u32, 1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -197,18 +191,15 @@ TEST_F(ValidateControlBlockTest,
ast::CaseSelectorList csl;
csl.push_back(create<ast::SintLiteral>(&i32, -1));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -234,25 +225,22 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueUint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::UintLiteral>(&u32, 0));
switch_body.push_back(create<ast::CaseStatement>(
std::move(csl_1), create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::UintLiteral>(&u32, 2));
csl_2.push_back(create<ast::UintLiteral>(&u32, 2));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl_2),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -278,8 +266,8 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
ast::CaseSelectorList csl_1;
csl_1.push_back(create<ast::SintLiteral>(&i32, 10));
switch_body.push_back(create<ast::CaseStatement>(
std::move(csl_1), create<ast::BlockStatement>()));
switch_body.push_back(
create<ast::CaseStatement>(csl_1, create<ast::BlockStatement>()));
ast::CaseSelectorList csl_2;
csl_2.push_back(create<ast::SintLiteral>(&i32, 0));
@@ -287,18 +275,15 @@ TEST_F(ValidateControlBlockTest, NonUniqueCaseSelectorValueSint_Fail) {
csl_2.push_back(create<ast::SintLiteral>(&i32, 2));
csl_2.push_back(create<ast::SintLiteral>(&i32, 10));
switch_body.push_back(create<ast::CaseStatement>(
Source{Source::Location{12, 34}}, std::move(csl_2),
create<ast::BlockStatement>()));
Source{Source::Location{12, 34}}, csl_2, create<ast::BlockStatement>()));
ast::CaseSelectorList default_csl;
auto* block_default = create<ast::BlockStatement>();
switch_body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
switch_body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(
create<ast::SwitchStatement>(std::move(cond), std::move(switch_body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, switch_body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -323,12 +308,11 @@ TEST_F(ValidateControlBlockTest, LastClauseLastStatementIsFallthrough_Fail) {
block_default->append(
create<ast::FallthroughStatement>(Source{Source::Location{12, 34}}));
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(std::move(default_csl),
std::move(block_default)));
body.push_back(create<ast::CaseStatement>(default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(block));
@@ -353,17 +337,15 @@ TEST_F(ValidateControlBlockTest, SwitchCase_Pass) {
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
std::move(default_csl),
std::move(block_default)));
default_csl, block_default));
ast::CaseSelectorList case_csl;
case_csl.push_back(create<ast::SintLiteral>(&i32, 5));
auto* block_case = create<ast::BlockStatement>();
body.push_back(
create<ast::CaseStatement>(std::move(case_csl), std::move(block_case)));
body.push_back(create<ast::CaseStatement>(case_csl, block_case));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(block)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(block)) << v()->error();
@@ -388,12 +370,11 @@ TEST_F(ValidateControlBlockTest, SwitchCaseAlias_Pass) {
auto* block_default = create<ast::BlockStatement>();
ast::CaseStatementList body;
body.push_back(create<ast::CaseStatement>(Source{Source::Location{12, 34}},
std::move(default_csl),
std::move(block_default)));
default_csl, block_default));
auto* block = create<ast::BlockStatement>();
block->append(create<ast::VariableDeclStatement>(std::move(var)));
block->append(create<ast::SwitchStatement>(std::move(cond), std::move(body)));
block->append(create<ast::VariableDeclStatement>(var));
block->append(create<ast::SwitchStatement>(cond, body));
mod()->AddConstructedType(&my_int);

View File

@@ -46,13 +46,12 @@ TEST_F(ValidateFunctionTest, VoidFunctionEndWithoutReturnStatement_Pass) {
ast::VariableList params;
ast::type::VoidType void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &void_type, std::move(body));
body->append(create<ast::VariableDeclStatement>(var));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod()));
@@ -64,12 +63,12 @@ TEST_F(ValidateFunctionTest,
// fn func -> void {}
ast::type::VoidType void_type;
ast::VariableList params;
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &void_type,
create<ast::BlockStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func", params,
&void_type, create<ast::BlockStatement>());
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod()));
@@ -86,10 +85,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatement_Fail) {
ast::VariableList params;
ast::type::VoidType void_type;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &i32, std::move(body));
mod()->AddFunction(std::move(func));
params, &i32, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@@ -103,10 +102,10 @@ TEST_F(ValidateFunctionTest, FunctionEndWithoutReturnStatementEmptyBody_Fail) {
ast::type::VoidType void_type;
ast::type::I32Type i32;
ast::VariableList params;
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params), &i32,
create<ast::BlockStatement>());
mod()->AddFunction(std::move(func));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "func", params,
&i32, create<ast::BlockStatement>());
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@@ -123,11 +122,10 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->DetermineFunctions(mod()->functions())) << td()->error();
EXPECT_TRUE(v()->ValidateFunctions(mod()->functions())) << v()->error();
@@ -143,10 +141,9 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementType_fail) {
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
std::move(return_expr)));
auto* func = create<ast::Function>("func", std::move(params), &void_type,
std::move(body));
mod()->AddFunction(std::move(func));
return_expr));
auto* func = create<ast::Function>("func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@@ -166,10 +163,9 @@ TEST_F(ValidateFunctionTest, FunctionTypeMustMatchReturnStatementTypeF32_fail) {
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(Source{Source::Location{12, 34}},
std::move(return_expr)));
auto* func =
create<ast::Function>("func", std::move(params), &f32, std::move(body));
mod()->AddFunction(std::move(func));
return_expr));
auto* func = create<ast::Function>("func", params, &f32, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@@ -190,22 +186,20 @@ TEST_F(ValidateFunctionTest, FunctionNamesMustBeUnique_fail) {
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func =
create<ast::Function>("func", std::move(params), &i32, std::move(body));
body->append(create<ast::ReturnStatement>(return_expr));
auto* func = create<ast::Function>("func", params, &i32, body);
ast::VariableList params_copy;
auto* body_copy = create<ast::BlockStatement>();
auto* return_expr_copy = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body_copy->append(create<ast::ReturnStatement>(std::move(return_expr_copy)));
auto* func_copy =
create<ast::Function>(Source{Source::Location{12, 34}}, "func",
std::move(params_copy), &i32, std::move(body_copy));
body_copy->append(create<ast::ReturnStatement>(return_expr_copy));
auto* func_copy = create<ast::Function>(Source{Source::Location{12, 34}},
"func", params_copy, &i32, body_copy);
mod()->AddFunction(std::move(func));
mod()->AddFunction(std::move(func_copy));
mod()->AddFunction(func);
mod()->AddFunction(func_copy);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
@@ -220,14 +214,13 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowed_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), std::move(call_params));
create<ast::IdentifierExpression>("func"), call_params);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::CallStatement>(std::move(call_expr)));
body0->append(create<ast::CallStatement>(call_expr));
body0->append(create<ast::ReturnStatement>());
auto* func0 =
create<ast::Function>("func", std::move(params0), &f32, std::move(body0));
mod()->AddFunction(std::move(func0));
auto* func0 = create<ast::Function>("func", params0, &f32, body0);
mod()->AddFunction(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
@@ -241,18 +234,17 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
ast::ExpressionList call_params;
auto* call_expr = create<ast::CallExpression>(
Source{Source::Location{12, 34}},
create<ast::IdentifierExpression>("func"), std::move(call_params));
var->set_constructor(std::move(call_expr));
create<ast::IdentifierExpression>("func"), call_params);
var->set_constructor(call_expr);
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(std::move(var)));
body0->append(create<ast::VariableDeclStatement>(var));
auto* return_expr = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
body0->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func0 =
create<ast::Function>("func", std::move(params0), &i32, std::move(body0));
mod()->AddFunction(std::move(func0));
body0->append(create<ast::ReturnStatement>(return_expr));
auto* func0 = create<ast::Function>("func", params0, &i32, body0);
mod()->AddFunction(func0);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
@@ -268,14 +260,13 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_NotVoid_Fail) {
create<ast::SintLiteral>(&i32, 0));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>(std::move(return_expr)));
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "vtx_main",
std::move(params), &i32, std::move(body));
body->append(create<ast::ReturnStatement>(return_expr));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}},
"vtx_main", params, &i32, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@@ -291,13 +282,12 @@ TEST_F(ValidateFunctionTest, Function_WithPipelineStage_WithParams_Fail) {
params.push_back(create<ast::Variable>("a", ast::StorageClass::kNone, &i32));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "vtx_func",
std::move(params), &void_type, std::move(body));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}},
"vtx_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@@ -313,14 +303,13 @@ TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func =
create<ast::Function>(Source{Source::Location{12, 34}}, "main",
std::move(params), &void_type, std::move(body));
auto* func = create<ast::Function>(Source{Source::Location{12, 34}}, "main",
params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kFragment, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(
@@ -335,11 +324,10 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Pass) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("vtx_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("vtx_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@@ -351,9 +339,8 @@ TEST_F(ValidateFunctionTest, OnePipelineStageFunctionMustBePresent_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("vtx_func", std::move(params), &void_type,
std::move(body));
mod()->AddFunction(std::move(func));
auto* func = create<ast::Function>("vtx_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));

View File

@@ -271,21 +271,19 @@ bool ValidatorImpl::ValidateSwitch(const ast::SwitchStatement* s) {
}
for (auto* selector : case_stmt->selectors()) {
auto* selector_ptr = selector;
if (cond_type != selector_ptr->type()) {
if (cond_type != selector->type()) {
set_error(case_stmt->source(),
"v-0026: the case selector values must have the same "
"type as the selector expression.");
return false;
}
auto v = static_cast<int32_t>(selector_ptr->type()->IsU32()
? selector_ptr->AsUint()->value()
: selector_ptr->AsSint()->value());
auto v = static_cast<int32_t>(selector->type()->IsU32()
? selector->AsUint()->value()
: selector->AsSint()->value());
if (selector_set.count(v)) {
auto v_str = selector_ptr->type()->IsU32()
? selector_ptr->AsUint()->to_str()
: selector_ptr->AsSint()->to_str();
auto v_str = selector->type()->IsU32() ? selector->AsUint()->to_str()
: selector->AsSint()->to_str();
set_error(case_stmt->source(),
"v-0027: a literal value must not appear more than once in "
"the case selectors for a switch statement: '" +

View File

@@ -67,8 +67,7 @@ TEST_F(ValidatorTest, DISABLED_AssignToScalar_Fail) {
auto* lhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 1));
auto* rhs = create<ast::IdentifierExpression>("my_var");
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
// TODO(sarahM0): Invalidate assignment to scalar.
ASSERT_TRUE(v()->has_error());
@@ -85,7 +84,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariable_Fail) {
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* assign = create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs));
Source{Source::Location{12, 34}}, lhs, rhs);
EXPECT_FALSE(td()->DetermineResultType(assign));
EXPECT_EQ(td()->error(),
@@ -105,7 +104,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInBlockStatement_Fail) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_FALSE(td()->DetermineStatements(body));
EXPECT_EQ(td()->error(),
@@ -121,17 +120,14 @@ TEST_F(ValidatorTest, AssignCompatibleTypes_Pass) {
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateResultTypes(&assign));
}
@@ -147,17 +143,14 @@ TEST_F(ValidatorTest, AssignIncompatibleTypes_Fail) {
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f));
auto* rhs_ptr = rhs;
ast::AssignmentStatement assign(Source{Source::Location{12, 34}},
std::move(lhs), std::move(rhs));
ast::AssignmentStatement assign(Source{Source::Location{12, 34}}, lhs, rhs);
td()->RegisterVariableForTesting(var);
EXPECT_TRUE(td()->DetermineResultType(&assign)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateResultTypes(&assign));
ASSERT_TRUE(v()->has_error());
@@ -177,19 +170,17 @@ TEST_F(ValidatorTest, AssignCompatibleTypesInBlockStatement_Pass) {
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
}
@@ -206,19 +197,17 @@ TEST_F(ValidatorTest, AssignIncompatibleTypesInBlockStatement_Fail) {
var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2)));
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.3f));
auto* rhs_ptr = rhs;
ast::BlockStatement block;
block.append(create<ast::VariableDeclStatement>(std::move(var)));
block.append(create<ast::VariableDeclStatement>(var));
block.append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(&block)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(&block));
ASSERT_TRUE(v()->has_error());
@@ -233,7 +222,7 @@ TEST_F(ValidatorTest, GlobalVariableWithStorageClass_Pass) {
auto* global_var =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kInput, &f32);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
<< v()->error();
}
@@ -244,7 +233,7 @@ TEST_F(ValidatorTest, GlobalVariableNoStorageClass_Fail) {
auto* global_var =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kNone, &f32);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(),
@@ -258,7 +247,7 @@ TEST_F(ValidatorTest, GlobalConstantWithStorageClass_Fail) {
ast::StorageClass::kInput, &f32);
global_var->set_is_const(true);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(
@@ -274,7 +263,7 @@ TEST_F(ValidatorTest, GlobalConstNoStorageClass_Pass) {
ast::StorageClass::kNone, &f32);
global_var->set_is_const(true);
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
}
@@ -289,7 +278,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* lhs = create<ast::IdentifierExpression>(
Source{Source::Location{12, 34}}, "not_global_var");
@@ -299,11 +288,10 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
auto* func = create<ast::Function>("my_func", std::move(params), &f32,
std::move(body));
mod()->AddFunction(std::move(func));
auto* func = create<ast::Function>("my_func", params, &f32, body);
mod()->AddFunction(func);
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(), "12:34: v-0006: 'not_global_var' is not declared");
@@ -322,7 +310,7 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* lhs = create<ast::IdentifierExpression>("global_var");
auto* rhs = create<ast::ScalarConstructorExpression>(
@@ -332,13 +320,12 @@ TEST_F(ValidatorTest, UsingUndefinedVariableGlobalVariable_Pass) {
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
body->append(create<ast::ReturnStatement>());
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
func->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func));
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@@ -358,24 +345,21 @@ TEST_F(ValidatorTest, UsingUndefinedVariableInnerScope_Fail) {
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* lhs =
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f));
auto* rhs_ptr = rhs;
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::IfStatement>(cond, body));
outer_body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(outer_body));
EXPECT_EQ(v()->error(), "12:34: v-0006: 'a' is not declared");
}
@@ -392,24 +376,22 @@ TEST_F(ValidatorTest, UsingUndefinedVariableOuterScope_Pass) {
auto* lhs =
create<ast::IdentifierExpression>(Source{Source::Location{12, 34}}, "a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 3.14f));
auto* rhs_ptr = rhs;
ast::type::BoolType bool_type;
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(create<ast::VariableDeclStatement>(std::move(var)));
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::VariableDeclStatement>(var));
outer_body->append(create<ast::IfStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
}
@@ -422,14 +404,14 @@ TEST_F(ValidatorTest, GlobalVariableUnique_Pass) {
create<ast::Variable>("global_var0", ast::StorageClass::kPrivate, &f32);
var0->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.1)));
mod()->AddGlobalVariable(std::move(var0));
mod()->AddGlobalVariable(var0);
auto* var1 =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var1",
ast::StorageClass::kPrivate, &f32);
var1->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 0)));
mod()->AddGlobalVariable(std::move(var1));
mod()->AddGlobalVariable(var1);
EXPECT_TRUE(v()->ValidateGlobalVariables(mod()->global_variables()))
<< v()->error();
@@ -444,14 +426,14 @@ TEST_F(ValidatorTest, GlobalVariableNotUnique_Fail) {
create<ast::Variable>("global_var", ast::StorageClass::kPrivate, &f32);
var0->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 0.1)));
mod()->AddGlobalVariable(std::move(var0));
mod()->AddGlobalVariable(var0);
auto* var1 =
create<ast::Variable>(Source{Source::Location{12, 34}}, "global_var",
ast::StorageClass::kPrivate, &f32);
var1->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 0)));
mod()->AddGlobalVariable(std::move(var1));
mod()->AddGlobalVariable(var1);
EXPECT_FALSE(v()->ValidateGlobalVariables(mod()->global_variables()));
EXPECT_EQ(v()->error(),
@@ -470,19 +452,17 @@ TEST_F(ValidatorTest, AssignToConstant_Fail) {
var->set_is_const(true);
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_FALSE(v()->ValidateStatements(body));
EXPECT_EQ(v()->error(), "12:34: v-0021: cannot re-assign a constant: 'a'");
@@ -501,7 +481,7 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
create<ast::Variable>("a", ast::StorageClass::kPrivate, &f32);
global_var->set_constructor(create<ast::ScalarConstructorExpression>(
create<ast::FloatLiteral>(&f32, 2.1)));
mod()->AddGlobalVariable(std::move(global_var));
mod()->AddGlobalVariable(global_var);
auto* var = create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
var->set_constructor(create<ast::ScalarConstructorExpression>(
@@ -509,14 +489,13 @@ TEST_F(ValidatorTest, GlobalVariableFunctionVariableNotUnique_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var)));
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func_ptr = func;
mod()->AddFunction(std::move(func));
Source{Source::Location{12, 34}}, var));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
EXPECT_FALSE(v()->Validate(mod())) << v()->error();
EXPECT_EQ(v()->error(), "12:34: v-0013: redeclared identifier 'a'");
}
@@ -540,16 +519,15 @@ TEST_F(ValidatorTest, RedeclaredIndentifier_Fail) {
ast::VariableList params;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var_a_float)));
auto* func = create<ast::Function>("my_func", std::move(params), &void_type,
std::move(body));
auto* func_ptr = func;
mod()->AddFunction(std::move(func));
Source{Source::Location{12, 34}}, var_a_float));
auto* func = create<ast::Function>("my_func", params, &void_type, body);
mod()->AddFunction(func);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func_ptr)) << td()->error();
EXPECT_TRUE(td()->DetermineFunction(func)) << td()->error();
EXPECT_FALSE(v()->Validate(mod()));
EXPECT_EQ(v()->error(), "12:34: v-0014: redeclared identifier 'a'");
}
@@ -568,7 +546,7 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
auto* cond = create<ast::ScalarConstructorExpression>(
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
auto* var_a_float =
create<ast::Variable>("a", ast::StorageClass::kNone, &f32);
@@ -576,10 +554,9 @@ TEST_F(ValidatorTest, RedeclaredIdentifierInnerScope_Pass) {
create<ast::FloatLiteral>(&f32, 3.14)));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::IfStatement>(cond, body));
outer_body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var_a_float)));
Source{Source::Location{12, 34}}, var_a_float));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_TRUE(v()->ValidateStatements(outer_body)) << v()->error();
@@ -607,13 +584,11 @@ TEST_F(ValidatorTest, DISABLED_RedeclaredIdentifierInnerScope_False) {
create<ast::BoolLiteral>(&bool_type, true));
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var)));
Source{Source::Location{12, 34}}, var));
auto* outer_body = create<ast::BlockStatement>();
outer_body->append(
create<ast::VariableDeclStatement>(std::move(var_a_float)));
outer_body->append(
create<ast::IfStatement>(std::move(cond), std::move(body)));
outer_body->append(create<ast::VariableDeclStatement>(var_a_float));
outer_body->append(create<ast::IfStatement>(cond, body));
EXPECT_TRUE(td()->DetermineStatements(outer_body)) << td()->error();
EXPECT_FALSE(v()->ValidateStatements(outer_body));
@@ -636,23 +611,21 @@ TEST_F(ValidatorTest, RedeclaredIdentifierDifferentFunctions_Pass) {
ast::VariableList params0;
auto* body0 = create<ast::BlockStatement>();
body0->append(create<ast::VariableDeclStatement>(
Source{Source::Location{12, 34}}, std::move(var0)));
Source{Source::Location{12, 34}}, var0));
body0->append(create<ast::ReturnStatement>());
auto* func0 = create<ast::Function>("func0", std::move(params0), &void_type,
std::move(body0));
auto* func0 = create<ast::Function>("func0", params0, &void_type, body0);
ast::VariableList params1;
auto* body1 = create<ast::BlockStatement>();
body1->append(create<ast::VariableDeclStatement>(
Source{Source::Location{13, 34}}, std::move(var1)));
Source{Source::Location{13, 34}}, var1));
body1->append(create<ast::ReturnStatement>());
auto* func1 = create<ast::Function>("func1", std::move(params1), &void_type,
std::move(body1));
auto* func1 = create<ast::Function>("func1", params1, &void_type, body1);
func1->add_decoration(
create<ast::StageDecoration>(ast::PipelineStage::kVertex, Source{}));
mod()->AddFunction(std::move(func0));
mod()->AddFunction(std::move(func1));
mod()->AddFunction(func0);
mod()->AddFunction(func1);
EXPECT_TRUE(td()->Determine()) << td()->error();
EXPECT_TRUE(v()->Validate(mod())) << v()->error();
@@ -668,19 +641,17 @@ TEST_F(ValidatorTest, VariableDeclNoConstructor_Pass) {
td()->RegisterVariableForTesting(var);
auto* lhs = create<ast::IdentifierExpression>("a");
auto* lhs_ptr = lhs;
auto* rhs = create<ast::ScalarConstructorExpression>(
create<ast::SintLiteral>(&i32, 2));
auto* rhs_ptr = rhs;
auto* body = create<ast::BlockStatement>();
body->append(create<ast::VariableDeclStatement>(std::move(var)));
body->append(create<ast::VariableDeclStatement>(var));
body->append(create<ast::AssignmentStatement>(
Source{Source::Location{12, 34}}, std::move(lhs), std::move(rhs)));
Source{Source::Location{12, 34}}, lhs, rhs));
EXPECT_TRUE(td()->DetermineStatements(body)) << td()->error();
ASSERT_NE(lhs_ptr->result_type(), nullptr);
ASSERT_NE(rhs_ptr->result_type(), nullptr);
ASSERT_NE(lhs->result_type(), nullptr);
ASSERT_NE(rhs->result_type(), nullptr);
EXPECT_TRUE(v()->ValidateStatements(body)) << v()->error();
}