Fix Validator regression reporting param not declared
This regression was accidentally introduced by my CL:
https://dawn-review.googlesource.com/c/tint/+/45382
I had removed too much of ValidatorImpl::ValidateFunction, including
its pushing of function parameters to the variable stack. As a result,,
any function parameters referenced by a function would fail the
Validator. This CL restores this bit, and adds a test for this case.
Bug: tint:642
Change-Id: I839057e73cabfb11631571ce806dec09f5d9f966
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/45500
Auto-Submit: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/validator/validator_function_test.cc b/src/validator/validator_function_test.cc
index 5c217eb..76aae57 100644
--- a/src/validator/validator_function_test.cc
+++ b/src/validator/validator_function_test.cc
@@ -173,7 +173,6 @@
"return type, returned '__u32', expected '__alias_tint_symbol_1__f32'");
}
-
TEST_F(ValidateFunctionTest, PipelineStage_MustBeUnique_Fail) {
// [[stage(fragment)]]
// [[stage(vertex)]]
@@ -229,5 +228,23 @@
"be present");
}
+TEST_F(ValidateFunctionTest, FunctionVarInitWithParam) {
+ // fn foo(bar : f32) -> void{
+ // var baz : f32 = bar;
+ // }
+
+ auto* bar = Var("bar", ty.f32(), ast::StorageClass::kFunction);
+ auto* baz = Var("baz", ty.f32(), ast::StorageClass::kFunction, Expr("bar"));
+
+ Func("foo", ast::VariableList{bar}, ty.void_(), ast::StatementList{Decl(baz)},
+ ast::DecorationList{
+ create<ast::StageDecoration>(ast::PipelineStage::kVertex),
+ });
+
+ ValidatorImpl& v = Build();
+
+ EXPECT_TRUE(v.Validate()) << v.error();
+}
+
} // namespace
} // namespace tint
diff --git a/src/validator/validator_impl.cc b/src/validator/validator_impl.cc
index 7f46edb..05e7f9e 100644
--- a/src/validator/validator_impl.cc
+++ b/src/validator/validator_impl.cc
@@ -170,9 +170,15 @@
bool ValidatorImpl::ValidateFunction(const ast::Function* func) {
// TODO(amaiorano): Remove ValidateFunction once we've moved all the statement
// validation to Resovler
+
+ variable_stack_.push_scope();
+ for (auto* param : func->params()) {
+ variable_stack_.set(param->symbol(), param);
+ }
if (!ValidateStatements(func->body())) {
return false;
}
+ variable_stack_.pop_scope();
return true;
}