[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>
diff --git a/src/validator_function_test.cc b/src/validator_function_test.cc
index 00606f6..abbc79a 100644
--- a/src/validator_function_test.cc
+++ b/src/validator_function_test.cc
@@ -241,7 +241,7 @@
   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 d978cc7..bd67899 100644
--- a/src/validator_impl.cc
+++ b/src/validator_impl.cc
@@ -49,7 +49,26 @@
   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 5ed21cf..3e38060 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 @@
   /// @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_;