Add break statement type determination.
This CL adds type determination for break statements.
Bug: tint:5
Change-Id: I5ca74a848ffd12fe404676910b08ea7518451eaf
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18829
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 87bf07a..8eed309 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -15,6 +15,7 @@
#include "src/type_determiner.h"
#include "src/ast/assignment_statement.h"
+#include "src/ast/break_statement.h"
#include "src/ast/scalar_constructor_expression.h"
#include "src/ast/type_constructor_expression.h"
@@ -75,6 +76,10 @@
auto a = stmt->AsAssign();
return DetermineResultType(a->lhs()) && DetermineResultType(a->rhs());
}
+ if (stmt->IsBreak()) {
+ auto b = stmt->AsBreak();
+ return DetermineResultType(b->conditional());
+ }
error_ = "unknown statement type for type determination";
return false;
diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc
index 471b9a1..a4c8087 100644
--- a/src/type_determiner_test.cc
+++ b/src/type_determiner_test.cc
@@ -19,6 +19,7 @@
#include "gtest/gtest.h"
#include "src/ast/assignment_statement.h"
+#include "src/ast/break_statement.h"
#include "src/ast/float_literal.h"
#include "src/ast/int_literal.h"
#include "src/ast/scalar_constructor_expression.h"
@@ -63,6 +64,20 @@
EXPECT_TRUE(rhs_ptr->result_type()->IsF32());
}
+TEST_F(TypeDeterminerTest, Stmt_Break) {
+ ast::type::I32Type i32;
+
+ auto cond = std::make_unique<ast::ScalarConstructorExpression>(
+ std::make_unique<ast::IntLiteral>(&i32, 2));
+ auto cond_ptr = cond.get();
+
+ ast::BreakStatement brk(ast::StatementCondition::kIf, std::move(cond));
+
+ EXPECT_TRUE(td()->DetermineResultType(&brk));
+ ASSERT_NE(cond_ptr->result_type(), nullptr);
+ EXPECT_TRUE(cond_ptr->result_type()->IsI32());
+}
+
TEST_F(TypeDeterminerTest, Expr_Constructor_Scalar) {
ast::type::F32Type f32;
ast::ScalarConstructorExpression s(