Skip to content

Commit 8d6bdd0

Browse files
jrpriceDawn LUCI CQ
authored andcommitted
[ir] Validate loop results
This fixes a fuzzer issue that was using an instruction result for multiple instructions. Fixed: 422822304 Change-Id: I5bfdc578a9dc79e5f4f3af128a04fd284c740238 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/245698 Reviewed-by: dan sinclair <[email protected]> Commit-Queue: dan sinclair <[email protected]> Auto-Submit: James Price <[email protected]>
1 parent d7fd9f0 commit 8d6bdd0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/tint/lang/core/ir/validator.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,6 +3340,8 @@ void Validator::CheckIf(const If* if_) {
33403340
}
33413341

33423342
void Validator::CheckLoop(const Loop* l) {
3343+
CheckResults(l);
3344+
33433345
// Note: Tasks are queued in reverse order of their execution
33443346
tasks_.Push([this, l] {
33453347
first_continues_.Remove(l); // No need for this any more. Free memory.

src/tint/lang/core/ir/validator_flow_control_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,25 @@ TEST_F(IR_ValidatorTest, Loop_EmptyBody) {
326326
)")) << res.Failure();
327327
}
328328

329+
TEST_F(IR_ValidatorTest, Loop_NullResult) {
330+
auto* f = b.Function("my_func", ty.void_());
331+
332+
auto* loop = b.Loop();
333+
loop->Body()->Append(b.Return(f));
334+
335+
loop->SetResults(Vector<InstructionResult*, 1>{nullptr});
336+
337+
f->Block()->Append(loop);
338+
f->Block()->Append(b.Return(f));
339+
340+
auto res = ir::Validate(mod);
341+
ASSERT_NE(res, Success);
342+
EXPECT_THAT(res.Failure().reason, testing::HasSubstr(R"(:3:5 error: loop: result is undefined
343+
undef = loop [b: $B2] { # loop_1
344+
^^^^^
345+
)")) << res.Failure();
346+
}
347+
329348
TEST_F(IR_ValidatorTest, Switch_RootBlock) {
330349
auto* switch_ = b.Switch(1_i);
331350
auto* def = b.DefaultCase(switch_);

0 commit comments

Comments
 (0)