transform/BoundArrayAccessors: Fix symbol renaming
We need to pre-clone the source program's symbols before creating the symbols `min` and `arrayLength`, otherwise the original program's symbols will be suffixed with a number to make them unique. Fixes Dawn tests that triggered this issue. Bug: tint:712 Change-Id: Ie1cf6cbcf2050a2ce1a94acf0ae131a06f635820 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/47761 Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
3dd4fae775
commit
f8313e5a6e
|
@ -29,6 +29,11 @@ BoundArrayAccessors::~BoundArrayAccessors() = default;
|
|||
Transform::Output BoundArrayAccessors::Run(const Program* in, const DataMap&) {
|
||||
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();
|
||||
|
||||
ctx.ReplaceAll([&](ast::ArrayAccessorExpression* expr) {
|
||||
return Transform(expr, &ctx);
|
||||
});
|
||||
|
|
|
@ -540,7 +540,7 @@ struct S {
|
|||
a : f32;
|
||||
b : array<f32>;
|
||||
};
|
||||
var<in> s : S;
|
||||
var<storage> s : S;
|
||||
|
||||
fn f() {
|
||||
var d : f32 = s.b[25];
|
||||
|
@ -554,7 +554,7 @@ struct S {
|
|||
b : array<f32>;
|
||||
};
|
||||
|
||||
var<in> s : S;
|
||||
var<storage> s : S;
|
||||
|
||||
fn f() {
|
||||
var d : f32 = s.b[min(u32(25), (arrayLength(s.b) - 1u))];
|
||||
|
@ -592,6 +592,49 @@ TEST_F(BoundArrayAccessorsTest, DISABLED_Scoped_Variable) {
|
|||
FAIL();
|
||||
}
|
||||
|
||||
// Check that existing use of min() and arrayLength() do not get renamed.
|
||||
TEST_F(BoundArrayAccessorsTest, DontRenameSymbols) {
|
||||
auto* src = R"(
|
||||
[[block]]
|
||||
struct S {
|
||||
a : f32;
|
||||
b : array<f32>;
|
||||
};
|
||||
|
||||
var<storage> s : S;
|
||||
|
||||
let c : u32 = 1u;
|
||||
|
||||
fn f() {
|
||||
let b : f32 = s.b[c];
|
||||
let x : i32 = min(1, 2);
|
||||
let y : u32 = arrayLength(s.b);
|
||||
}
|
||||
)";
|
||||
|
||||
auto* expect = R"(
|
||||
[[block]]
|
||||
struct S {
|
||||
a : f32;
|
||||
b : array<f32>;
|
||||
};
|
||||
|
||||
var<storage> s : S;
|
||||
|
||||
let c : u32 = 1u;
|
||||
|
||||
fn f() {
|
||||
let b : f32 = s.b[min(u32(c), (arrayLength(s.b) - 1u))];
|
||||
let x : i32 = min(1, 2);
|
||||
let y : u32 = arrayLength(s.b);
|
||||
}
|
||||
)";
|
||||
|
||||
auto got = Run<BoundArrayAccessors>(src);
|
||||
|
||||
EXPECT_EQ(expect, str(got));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace transform
|
||||
} // namespace tint
|
||||
|
|
Loading…
Reference in New Issue