From 4b04721075ca97a6118a50a398641d8c84e95bbf Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 27 May 2022 20:16:26 +0000 Subject: [PATCH] tint/resolver: Ensure that validation is done before CollectTextureSamplerPairs() CollectTextureSamplerPairs() makes assumptions that the argument types are correct. If they're not, you can end up with NPEs. Bug: chromium:1327698 Change-Id: Ic9b14126c4b7129bb080f01c90f692b59cd1631e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91850 Reviewed-by: Antonio Maiorano Kokoro: Kokoro Commit-Queue: Antonio Maiorano Auto-Submit: Ben Clayton Commit-Queue: Ben Clayton --- src/tint/resolver/resolver.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 1dcedf981c..84031093da 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1553,6 +1553,14 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr, auto* call = builder_->create(expr, target, std::move(args), current_statement_, sem::Constant{}, has_side_effects); + target->AddCallSite(call); + + call->Behaviors() = arg_behaviors + target->Behaviors(); + + if (!validator_.FunctionCall(call, current_statement_)) { + return nullptr; + } + if (current_function_) { // Note: Requires called functions to be resolved first. // This is currently guaranteed as functions must be declared before @@ -1568,17 +1576,10 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr, current_function_->AddTransitivelyReferencedGlobal(var); } + // Note: Validation *must* be performed before calling this method. CollectTextureSamplerPairs(target, call->Arguments()); } - target->AddCallSite(call); - - call->Behaviors() = arg_behaviors + target->Behaviors(); - - if (!validator_.FunctionCall(call, current_statement_)) { - return nullptr; - } - return call; }