diff --git a/src/transform/canonicalize_entry_point_io.cc b/src/transform/canonicalize_entry_point_io.cc index 72c88b4f4b..f655b30b91 100644 --- a/src/transform/canonicalize_entry_point_io.cc +++ b/src/transform/canonicalize_entry_point_io.cc @@ -32,6 +32,10 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in, ProgramBuilder out; CloneContext ctx(&out, in); + // Start by cloning all the symbols. This ensures that the authored symbols + // won't get renamed if they collide with new symbols below. + ctx.CloneSymbols(); + // Strip entry point IO decorations from struct declarations. // TODO(jrprice): This code is duplicated with the SPIR-V transform. for (auto* ty : ctx.src->AST().ConstructedTypes()) { diff --git a/src/transform/canonicalize_entry_point_io_test.cc b/src/transform/canonicalize_entry_point_io_test.cc index a7e4bf7009..aadf916c29 100644 --- a/src/transform/canonicalize_entry_point_io_test.cc +++ b/src/transform/canonicalize_entry_point_io_test.cc @@ -503,6 +503,29 @@ fn frag_main(tint_symbol : tint_symbol_1) -> tint_symbol_2 { EXPECT_EQ(expect, str(got)); } +TEST_F(CanonicalizeEntryPointIOTest, DontRenameSymbols) { + auto* src = R"( +[[stage(fragment)]] +fn tint_symbol_1([[location(0)]] col : f32) { +} +)"; + + auto* expect = R"( +struct tint_symbol_2 { + [[location(0)]] + col : f32; +}; + +[[stage(fragment)]] +fn tint_symbol_1(tint_symbol : tint_symbol_2) { +} +)"; + + auto got = Run(src); + + EXPECT_EQ(expect, str(got)); +} + } // namespace } // namespace transform } // namespace tint