diff --git a/src/writer/hlsl/generator_impl.cc b/src/writer/hlsl/generator_impl.cc index 5ba656adc7..a85a555fcd 100644 --- a/src/writer/hlsl/generator_impl.cc +++ b/src/writer/hlsl/generator_impl.cc @@ -2912,6 +2912,9 @@ bool GeneratorImpl::EmitType(std::ostream& out, ast::Access access, const std::string& name, bool* name_printed /* = nullptr */) { + if (name_printed) { + *name_printed = false; + } switch (storage_class) { case ast::StorageClass::kStorage: if (access != ast::Access::kRead) { @@ -3091,11 +3094,11 @@ bool GeneratorImpl::EmitTypeAndName(std::ostream& out, ast::StorageClass storage_class, ast::Access access, const std::string& name) { - bool printed_name = false; - if (!EmitType(out, type, storage_class, access, name, &printed_name)) { + bool name_printed = false; + if (!EmitType(out, type, storage_class, access, name, &name_printed)) { return false; } - if (!name.empty() && !printed_name) { + if (!name.empty() && !name_printed) { out << " " << name; } return true; diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc index f4efca46d7..f9cfe89924 100644 --- a/src/writer/msl/generator_impl.cc +++ b/src/writer/msl/generator_impl.cc @@ -1930,6 +1930,9 @@ bool GeneratorImpl::EmitType(std::ostream& out, const sem::Type* type, const std::string& name, bool* name_printed /* = nullptr */) { + if (name_printed) { + *name_printed = false; + } if (auto* atomic = type->As()) { if (atomic->Type()->Is()) { out << "atomic_int"; @@ -2000,12 +2003,12 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << " "; if (ptr->StoreType()->Is()) { std::string inner = "(*" + name + ")"; - if (name_printed) { - *name_printed = true; - } if (!EmitType(out, ptr->StoreType(), inner)) { return false; } + if (name_printed) { + *name_printed = true; + } } else { if (!EmitType(out, ptr->StoreType(), "")) { return false;