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,10 +598,14 @@ bool GeneratorImpl::EmitVariable(ast::Variable* var) {
|
|||
}
|
||||
}
|
||||
|
||||
out_ << " " << program_->Symbols().NameFor(var->symbol()) << " : ";
|
||||
if (!EmitType(sem->DeclaredType())) {
|
||||
out_ << " " << program_->Symbols().NameFor(var->symbol());
|
||||
|
||||
if (var->declared_type()) {
|
||||
out_ << " : ";
|
||||
if (!EmitType(var->declared_type())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (var->constructor() != nullptr) {
|
||||
out_ << " = ";
|
||||
|
|
|
@ -68,6 +68,20 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Private) {
|
|||
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 wgsl
|
||||
} // namespace writer
|
||||
|
|
Loading…
Reference in New Issue