diff --git a/src/transform/spirv.cc b/src/transform/spirv.cc index bbbff3f4f7..c9da68b1bb 100644 --- a/src/transform/spirv.cc +++ b/src/transform/spirv.cc @@ -324,7 +324,7 @@ void Spirv::HoistToOutputVariables(CloneContext& ctx, // Recurse into struct members. auto* struct_ty = ty->UnwrapAliasIfNeeded()->As(); for (auto* member : struct_ty->impl()->members()) { - member_accesses.push_back(member->symbol()); + member_accesses.push_back(ctx.Clone(member->symbol())); HoistToOutputVariables(ctx, func, member->type(), member->decorations(), member_accesses, store_value, stores); member_accesses.pop_back(); diff --git a/src/transform/spirv_test.cc b/src/transform/spirv_test.cc index 7e44dee142..efec401e04 100644 --- a/src/transform/spirv_test.cc +++ b/src/transform/spirv_test.cc @@ -442,6 +442,47 @@ fn frag_main() -> void { EXPECT_EQ(expect, str(got)); } +TEST_F(SpirvTest, HandleEntryPointIOTypes_WithPrivateGlobalVariable) { + // Test with a global variable to ensure that symbols are cloned correctly. + // crbug.com/tint/701 + auto* src = R"( +var x : f32; + +struct VertexOutput { + [[builtin(position)]] Position : vec4; +}; + +[[stage(vertex)]] +fn main() -> VertexOutput { + return VertexOutput(vec4()); +} +)"; + + auto* expect = R"( +var x : f32; + +struct VertexOutput { + Position : vec4; +}; + +[[builtin(position)]] var tint_symbol_4 : vec4; + +fn tint_symbol_5(tint_symbol_3 : VertexOutput) -> void { + tint_symbol_4 = tint_symbol_3.Position; +} + +[[stage(vertex)]] +fn main() -> void { + tint_symbol_5(VertexOutput(vec4())); + return; +} +)"; + + auto got = Run(src); + + EXPECT_EQ(expect, str(got)); +} + TEST_F(SpirvTest, HandleSampleMaskBuiltins_Basic) { auto* src = R"( [[builtin(sample_index)]] var sample_index : u32;