[validation] checks if function used in entry point exists

This CL check validation rule v-0019: Functions used in entry points must exist.

Bug: tint: 6
Change-Id: Ic4d4702cac53dcdaa1207425a6214d53cacb2442
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27100
Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
Reviewed-by: David Neto <dneto@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Sarah Mashayekhi 2020-08-20 21:25:39 +00:00 committed by Commit Bot service account
parent 255cfe829f
commit 3c9fee13b9
3 changed files with 26 additions and 1 deletions

View File

@ -241,7 +241,7 @@ TEST_F(ValidateFunctionTest, RecursionIsNotAllowedExpr_Fail) {
EXPECT_EQ(v.error(), "12:34: v-0004: recursion is not allowed: 'func'");
}
TEST_F(ValidateFunctionTest, DISABLED_EntryPointFunctionMissing_Fail) {
TEST_F(ValidateFunctionTest, EntryPointFunctionMissing_Fail) {
// entry_point vertex as "main" = vtx_main
// fn frag_main() -> void { return; }
ast::type::VoidType void_type;

View File

@ -49,7 +49,26 @@ bool ValidatorImpl::Validate(const ast::Module* module) {
if (!ValidateFunctions(module->functions())) {
return false;
}
// ValidateEntryPoints must be done after populating function_stack_
if (!ValidateEntryPoints(module->entry_points())) {
return false;
}
function_stack_.pop_scope();
return true;
}
bool ValidatorImpl::ValidateEntryPoints(const ast::EntryPointList& eps) {
for (const auto& ep : eps) {
auto* ep_ptr = ep.get();
if (!function_stack_.has(ep_ptr->function_name())) {
set_error(ep_ptr->source(),
"v-0019: Function used in entry point does not exist: '" +
ep_ptr->function_name() + "'");
return false;
}
}
return true;
}

View File

@ -20,6 +20,7 @@
#include "src/ast/assignment_statement.h"
#include "src/ast/call_expression.h"
#include "src/ast/entry_point.h"
#include "src/ast/expression.h"
#include "src/ast/identifier_expression.h"
#include "src/ast/module.h"
@ -105,6 +106,11 @@ class ValidatorImpl {
/// @param expr the call to validate
/// @returns true if successful
bool ValidateCallExpr(const ast::CallExpression* expr);
/// Validates entry points
/// this funtion must be called after populating function_stack_
/// @param eps the vector of entry points to check
/// @return true if the validation was successful
bool ValidateEntryPoints(const ast::EntryPointList& eps);
private:
std::string error_;