[validation] validate if entry point functions return void

This CL validates following validation rule:
v-0024: Entry point functions return void

Bug: tint: 6
Change-Id: I420781008016af110cb0d3d65fc018a1301efeae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27120
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Sarah Mashayekhi 2020-08-21 15:40:43 +00:00 committed by Commit Bot service account
parent 1026fe3d27
commit e871e48df0
2 changed files with 10 additions and 2 deletions

View File

@ -286,7 +286,7 @@ TEST_F(ValidateFunctionTest, EntryPointFunctionExist_Pass) {
EXPECT_TRUE(v.Validate(mod())) << v.error();
}
TEST_F(ValidateFunctionTest, DISABLED_EntryPointFunctionNotVoid_Fail) {
TEST_F(ValidateFunctionTest, EntryPointFunctionNotVoid_Fail) {
// entry_point vertex as "main" = vtx_main
// fn vtx_main() -> i32 { return 0; }
ast::type::I32Type i32;
@ -301,7 +301,7 @@ TEST_F(ValidateFunctionTest, DISABLED_EntryPointFunctionNotVoid_Fail) {
func->set_body(std::move(body));
auto entry_point = std::make_unique<ast::EntryPoint>(
ast::PipelineStage::kVertex, "main", "vtx_main");
Source{12, 34}, ast::PipelineStage::kVertex, "main", "vtx_main");
mod()->AddFunction(std::move(func));
mod()->AddEntryPoint(std::move(entry_point));

View File

@ -68,6 +68,14 @@ bool ValidatorImpl::ValidateEntryPoints(const ast::EntryPointList& eps) {
ep_ptr->function_name() + "'");
return false;
}
ast::Function* func;
function_stack_.get(ep_ptr->function_name(), &func);
if (!func->return_type()->IsVoid()) {
set_error(ep_ptr->source(),
"v-0024: Entry point function must return void: '" +
ep_ptr->function_name() + "'");
return false;
}
}
return true;
}