tint/renamer: Preserve diagnostic control names

Add a Dawn E2E test to make sure that diagnostic controls work through
the whole shader compilation flow.

Bug: tint:1809
Fixed: chromium:1410930
Change-Id: Icea31cfadbbc182008a8a07efcddb402954dd1c7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117980
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: James Price <jrprice@google.com>
This commit is contained in:
James Price
2023-01-28 00:37:42 +00:00
committed by Dawn LUCI CQ
parent 4ec8e5c7f8
commit 7ce72de3a5
3 changed files with 96 additions and 0 deletions

View File

@@ -1313,6 +1313,9 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
});
}
},
[&](const ast::DiagnosticControl* diagnostic) {
preserved_identifiers.Add(diagnostic->rule_name);
},
[&](const ast::TypeName* type_name) {
if (is_type_short_name(type_name->name)) {
preserved_type_names.Add(type_name);

View File

@@ -189,6 +189,48 @@ fn tint_symbol() {
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
}
TEST_F(RenamerTest, PreserveDiagnosticControls) {
auto* src = R"(
diagnostic(off, unreachable_code);
@diagnostic(off, derivative_uniformity)
@fragment
fn entry(@location(0) value : f32) -> @location(0) f32 {
if (value > 0) {
return dpdx(value);
return 0.0;
}
return 1.0;
}
)";
auto* expect = R"(
diagnostic(off, unreachable_code);
@diagnostic(off, derivative_uniformity) @fragment
fn tint_symbol(@location(0) tint_symbol_1 : f32) -> @location(0) f32 {
if ((tint_symbol_1 > 0)) {
return dpdx(tint_symbol_1);
return 0.0;
}
return 1.0;
}
)";
auto got = Run<Renamer>(src);
EXPECT_EQ(expect, str(got));
auto* data = got.data.Get<Renamer::Data>();
ASSERT_NE(data, nullptr);
Renamer::Data::Remappings expected_remappings = {
{"entry", "tint_symbol"},
{"value", "tint_symbol_1"},
};
EXPECT_THAT(data->remappings, ContainerEq(expected_remappings));
}
TEST_F(RenamerTest, PreserveUnicode) {
auto src = R"(
@fragment