Fix issue resolving address of numeric.

This CL fixes up a clusterfuzz issue where the address of a
numeric was take in a case selector leading to a nullptr.

Bug: chromium:1376865
Change-Id: I3b78a17e1c47263e18d2d272ff28c2cc8be79a0e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106540
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-10-20 14:56:45 +00:00 committed by Dawn LUCI CQ
parent 882b38a2f5
commit 481b2ed959
2 changed files with 11 additions and 0 deletions

View File

@ -3113,6 +3113,9 @@ sem::SwitchStatement* Resolver::SwitchStatement(const ast::SwitchStatement* stmt
continue; continue;
} }
auto* sem_expr = Expression(sel->expr); auto* sem_expr = Expression(sel->expr);
if (!sem_expr) {
return false;
}
types.Push(sem_expr->Type()->UnwrapRef()); types.Push(sem_expr->Type()->UnwrapRef());
} }
} }

View File

@ -135,6 +135,14 @@ TEST_F(ResolverTest, Stmt_Case) {
EXPECT_EQ(sem->Cases()[1]->Selectors().size(), 1u); EXPECT_EQ(sem->Cases()[1]->Selectors().size(), 1u);
} }
TEST_F(ResolverTest, Stmt_Case_AddressOf_Invalid) {
auto* cond_var = Var("i", ty.i32());
WrapInFunction(cond_var, Switch("i", Case(CaseSelector(AddressOf(1_a)), Block())));
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "error: cannot take the address of expression");
}
TEST_F(ResolverTest, Stmt_Block) { TEST_F(ResolverTest, Stmt_Block) {
auto* v = Var("v", ty.f32()); auto* v = Var("v", ty.f32());
auto* lhs = Expr("v"); auto* lhs = Expr("v");