transform/CanonicalizeEntryPointIO: Fix symbol renaming

Pre-clone the program's symbols at the start of the transform,
otherwise the original program's symbols may get mangled. This causes
problems for Dawn when the entry point name is changed.

Change-Id: I414c798fb5f51afe44e8b97619f77452f97f0782
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47824
Commit-Queue: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
James Price 2021-04-14 22:08:48 +00:00 committed by Commit Bot service account
parent edd4d3cc3b
commit 43b84d69dd
2 changed files with 27 additions and 0 deletions

View File

@ -32,6 +32,10 @@ Transform::Output CanonicalizeEntryPointIO::Run(const Program* in,
ProgramBuilder out; ProgramBuilder out;
CloneContext ctx(&out, in); 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. // Strip entry point IO decorations from struct declarations.
// TODO(jrprice): This code is duplicated with the SPIR-V transform. // TODO(jrprice): This code is duplicated with the SPIR-V transform.
for (auto* ty : ctx.src->AST().ConstructedTypes()) { for (auto* ty : ctx.src->AST().ConstructedTypes()) {

View File

@ -503,6 +503,29 @@ fn frag_main(tint_symbol : tint_symbol_1) -> tint_symbol_2 {
EXPECT_EQ(expect, str(got)); 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<CanonicalizeEntryPointIO>(src);
EXPECT_EQ(expect, str(got));
}
} // namespace } // namespace
} // namespace transform } // namespace transform
} // namespace tint } // namespace tint