writer/wgsl: Handle inferred-type variable declarations
Fixes a null-pointer deference crash. Bug: tint:672 Change-Id: Icfcb1c8754950ea0e074a0b392d0b34748a13827 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48225 Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
238de88266
commit
8198d57ff2
|
@ -598,9 +598,13 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out_ << " " << program_->Symbols().NameFor(var->symbol()) << " : ";
|
out_ << " " << program_->Symbols().NameFor(var->symbol());
|
||||||
if (!EmitType(sem->DeclaredType())) {
|
|
||||||
return false;
|
if (var->declared_type()) {
|
||||||
|
out_ << " : ";
|
||||||
|
if (!EmitType(var->declared_type())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (var->constructor() != nullptr) {
|
if (var->constructor() != nullptr) {
|
||||||
|
|
|
@ -68,6 +68,20 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
||||||
EXPECT_EQ(gen.result(), " var<private> a : f32;\n");
|
EXPECT_EQ(gen.result(), " var<private> a : f32;\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_InferredType) {
|
||||||
|
auto* var = Var("a", nullptr, ast::StorageClass::kFunction, Expr(123));
|
||||||
|
|
||||||
|
auto* stmt = create<ast::VariableDeclStatement>(var);
|
||||||
|
WrapInFunction(stmt);
|
||||||
|
|
||||||
|
GeneratorImpl& gen = Build();
|
||||||
|
|
||||||
|
gen.increment_indent();
|
||||||
|
|
||||||
|
ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.error();
|
||||||
|
EXPECT_EQ(gen.result(), " var a = 123;\n");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace wgsl
|
} // namespace wgsl
|
||||||
} // namespace writer
|
} // namespace writer
|
||||||
|
|
Loading…
Reference in New Issue