[type-determiner] Handle pointer arguments.

Currently if the type determiner is determining an identifier it will
wrap it into a pointer if it isn't a constant. This CL updates to make
sure we don't already have a pointer as otherwise we endup with a double
pointer.

Bug: tint:216
Change-Id: I2f8c83bd8680df6c3aef31e1cbb754fdff709b4b
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/28442
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-09-16 21:20:36 +00:00 committed by Commit Bot service account
parent 43759bff1c
commit 5e989306e5
2 changed files with 28 additions and 0 deletions

View File

@ -719,6 +719,8 @@ bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) {
// the pointer around the variable type. // the pointer around the variable type.
if (var->is_const()) { if (var->is_const()) {
expr->set_result_type(var->type()); expr->set_result_type(var->type());
} else if (var->type()->IsPointer()) {
expr->set_result_type(var->type());
} else { } else {
expr->set_result_type( expr->set_result_type(
ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>( ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(

View File

@ -808,6 +808,32 @@ TEST_F(TypeDeterminerTest, Expr_Identifier_FunctionVariable) {
EXPECT_TRUE(my_var_ptr->result_type()->AsPointer()->type()->IsF32()); EXPECT_TRUE(my_var_ptr->result_type()->AsPointer()->type()->IsF32());
} }
TEST_F(TypeDeterminerTest, Expr_Identifier_Function_Ptr) {
ast::type::F32Type f32;
ast::type::PointerType ptr(&f32, ast::StorageClass::kFunction);
auto my_var = std::make_unique<ast::IdentifierExpression>("my_var");
auto* my_var_ptr = my_var.get();
auto body = std::make_unique<ast::BlockStatement>();
body->append(std::make_unique<ast::VariableDeclStatement>(
std::make_unique<ast::Variable>("my_var", ast::StorageClass::kNone,
&ptr)));
body->append(std::make_unique<ast::AssignmentStatement>(
std::move(my_var),
std::make_unique<ast::IdentifierExpression>("my_var")));
ast::Function f("my_func", {}, &f32);
f.set_body(std::move(body));
EXPECT_TRUE(td()->DetermineFunction(&f));
ASSERT_NE(my_var_ptr->result_type(), nullptr);
EXPECT_TRUE(my_var_ptr->result_type()->IsPointer());
EXPECT_TRUE(my_var_ptr->result_type()->AsPointer()->type()->IsF32());
}
TEST_F(TypeDeterminerTest, Expr_Identifier_Function) { TEST_F(TypeDeterminerTest, Expr_Identifier_Function) {
ast::type::F32Type f32; ast::type::F32Type f32;