Validator: Strip out unreachable code

A large chunk of validation is now handled by the IntrinsicTable. Remove this.

Also fail validation and propagate diagnostics from the Program to the validator if attempting to validate a broken program. This should prevent undefined behaviour if the user forgets to check the program.IsValid() after parsing.

Change-Id: I2972e8ce296d6d6fca318cee48bc6929e5ed52db
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/41549
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-02-17 01:08:41 +00:00
committed by Commit Bot service account
parent 4602ce7195
commit 43a160dcbb
3 changed files with 31 additions and 464 deletions

View File

@@ -48,12 +48,12 @@ class Function : public Castable<Function, CallTarget> {
};
/// Constructor
/// @param ast the ast::Function
/// @param declaration the ast::Function
/// @param referenced_module_vars the referenced module variables
/// @param local_referenced_module_vars the locally referenced module
/// variables
/// @param ancestor_entry_points the ancestor entry points
Function(ast::Function* ast,
Function(ast::Function* declaration,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<Symbol> ancestor_entry_points);
@@ -61,6 +61,9 @@ class Function : public Castable<Function, CallTarget> {
/// Destructor
~Function() override;
/// @returns the ast::Function declaration
ast::Function* Declaration() const { return declaration_; }
/// Note: If this function calls other functions, the return will also include
/// all of the referenced variables from the callees.
/// @returns the referenced module variables
@@ -143,6 +146,7 @@ class Function : public Castable<Function, CallTarget> {
const std::vector<std::pair<const Variable*, BindingInfo>>
ReferencedSampledTextureVariablesImpl(bool multisampled) const;
ast::Function* const declaration_;
std::vector<const Variable*> const referenced_module_vars_;
std::vector<const Variable*> const local_referenced_module_vars_;
std::vector<Symbol> const ancestor_entry_points_;

View File

@@ -45,11 +45,12 @@ ParameterList GetParameters(ast::Function* ast) {
} // namespace
Function::Function(ast::Function* ast,
Function::Function(ast::Function* declaration,
std::vector<const Variable*> referenced_module_vars,
std::vector<const Variable*> local_referenced_module_vars,
std::vector<Symbol> ancestor_entry_points)
: Base(ast->return_type(), GetParameters(ast)),
: Base(declaration->return_type(), GetParameters(declaration)),
declaration_(declaration),
referenced_module_vars_(std::move(referenced_module_vars)),
local_referenced_module_vars_(std::move(local_referenced_module_vars)),
ancestor_entry_points_(std::move(ancestor_entry_points)) {}