[ir] Validate that break_if condition is not undef
Fixed: 441540931
Change-Id: I8c43472d774b77403cf51e4f838b9119e80046fd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/259556
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/core/ir/validator.cc b/src/tint/lang/core/ir/validator.cc
index bef89f4d..9cc9d0c 100644
--- a/src/tint/lang/core/ir/validator.cc
+++ b/src/tint/lang/core/ir/validator.cc
@@ -3655,6 +3655,11 @@
}
void Validator::CheckBreakIf(const BreakIf* b) {
+ if (b->Condition() == nullptr) {
+ AddError(b) << "break_if condition cannot be nullptr";
+ return;
+ }
+
auto* loop = b->Loop();
if (loop == nullptr) {
AddError(b) << "has no associated loop";
diff --git a/src/tint/lang/core/ir/validator_flow_control_test.cc b/src/tint/lang/core/ir/validator_flow_control_test.cc
index 4a599ab..b49da34 100644
--- a/src/tint/lang/core/ir/validator_flow_control_test.cc
+++ b/src/tint/lang/core/ir/validator_flow_control_test.cc
@@ -1272,6 +1272,25 @@
)")) << res.Failure();
}
+TEST_F(IR_ValidatorTest, BreakIf_UndefCondition) {
+ auto* f = b.Function("my_func", ty.void_());
+ b.Append(f->Block(), [&] {
+ auto* loop = b.Loop();
+ b.Append(loop->Body(), [&] { b.Continue(loop); });
+ b.Append(loop->Continuing(), [&] { b.BreakIf(loop, nullptr); });
+ b.Return(f);
+ });
+
+ auto res = ir::Validate(mod);
+ ASSERT_NE(res, Success);
+ EXPECT_THAT(res.Failure().reason,
+ testing::HasSubstr(
+ R"(:8:9 error: break_if: break_if condition cannot be nullptr
+ break_if undef # -> [t: exit_loop loop_1, f: $B2]
+ ^^^^^^^^^^^^^^
+)")) << res.Failure();
+}
+
TEST_F(IR_ValidatorTest, BreakIf_NextIterUnexpectedValues) {
auto* f = b.Function("my_func", ty.void_());
b.Append(f->Block(), [&] {