From 3c9fee13b97b12be25e850106fbb0f55d0bd6d18 Mon Sep 17 00:00:00 2001 From: Sarah Mashayekhi Date: Thu, 20 Aug 2020 21:25:39 +0000 Subject: [PATCH] [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 Reviewed-by: David Neto Reviewed-by: dan sinclair --- src/validator_function_test.cc | 2 +- src/validator_impl.cc | 19 +++++++++++++++++++ src/validator_impl.h | 6 ++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/validator_function_test.cc b/src/validator_function_test.cc index 00606f6aab..abbc79a802 100644 --- a/src/validator_function_test.cc +++ b/src/validator_function_test.cc @@ -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; diff --git a/src/validator_impl.cc b/src/validator_impl.cc index d978cc7285..bd678995ad 100644 --- a/src/validator_impl.cc +++ b/src/validator_impl.cc @@ -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; } diff --git a/src/validator_impl.h b/src/validator_impl.h index 5ed21cf8a5..3e38060eb4 100644 --- a/src/validator_impl.h +++ b/src/validator_impl.h @@ -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_;