[type-determiner] Determine call parameter types.
This CL adds type determination for the call parameters.
Bug: tint:5
Change-Id: I488718bd7a4c1f2304a1c17554b8354d184dc159
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19760
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 1be0c42..aa9d026 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -284,6 +284,12 @@
}
bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
+ for (const auto& param : expr->params()) {
+ if (!DetermineResultType(param.get())) {
+ return false;
+ }
+ }
+
if (!DetermineResultType(expr->func())) {
return false;
}
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index b722511..d59d21f 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -545,6 +545,32 @@
EXPECT_TRUE(call.result_type()->IsF32());
}
+TEST_F(TypeDeterminerTest, Expr_Call_WithParams) {
+ ast::type::F32Type f32;
+
+ ast::VariableList params;
+ auto func =
+ std::make_unique<ast::Function>("my_func", std::move(params), &f32);
+ ast::Module m;
+ m.AddFunction(std::move(func));
+
+ // Register the function
+ EXPECT_TRUE(td()->Determine(&m));
+
+ ast::ExpressionList call_params;
+ call_params.push_back(std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::FloatLiteral>(&f32, 2.4)));
+
+ auto* param_ptr = call_params.back().get();
+
+ ast::CallExpression call(
+ std::make_unique<ast::IdentifierExpression>("my_func"),
+ std::move(call_params));
+ EXPECT_TRUE(td()->DetermineResultType(&call));
+ ASSERT_NE(param_ptr->result_type(), nullptr);
+ EXPECT_TRUE(param_ptr->result_type()->IsF32());
+}
+
TEST_F(TypeDeterminerTest, Expr_Cast) {
ast::type::F32Type f32;
ast::CastExpression cast(&f32,