Set function storage class in type determiner.

If a non-const variable in a function has a kNone storage class we
update it to kFunction. If there is a storage class other then kFunction
we emit an error.

Bug: tint:5
Change-Id: If45eb91bd0a0095e625eb1d0e1d1e361c784e35d
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19102
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair
2020-04-08 19:58:20 +00:00
committed by dan sinclair
parent 9459dbf3ab
commit ee8ae04472
9 changed files with 150 additions and 41 deletions

View File

@@ -16,13 +16,13 @@
#include "gtest/gtest.h"
#include "src/ast/binary_expression.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type/f32_type.h"
#include "src/ast/type/i32_type.h"
#include "src/ast/type/vector_type.h"
#include "src/ast/type_constructor_expression.h"
#include "src/context.h"
#include "src/type_determiner.h"
#include "src/writer/spirv/builder.h"
@@ -69,26 +69,28 @@ TEST_F(BuilderTest, Binary_Add_Integer_Vectors) {
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
std::make_unique<ast::IntLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
std::make_unique<ast::IntLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
auto lhs = std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::IntLiteral>(&i32, 1)));
auto lhs =
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
std::make_unique<ast::IntLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
std::make_unique<ast::IntLiteral>(&i32, 1)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::IntLiteral>(&i32, 1)));
auto rhs = std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::IntLiteral>(&i32, 1)));
auto rhs =
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::BinaryExpression expr(
ast::BinaryOp::kAdd, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
@@ -140,26 +142,28 @@ TEST_F(BuilderTest, Binary_Add_Float_Vectors) {
ast::ExpressionList vals;
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
auto lhs = std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
auto lhs =
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
vals.push_back(std::make_unique<ast::ScalarConstructorExpression>(
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
auto rhs = std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
std::make_unique<ast::FloatLiteral>(&f32, 1.f)));
auto rhs =
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::BinaryExpression expr(
ast::BinaryOp::kAdd, std::move(lhs), std::move(rhs));
ast::BinaryExpression expr(ast::BinaryOp::kAdd, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();