tint/resolver: Warn for unknown diagnostic rules

Suggest alternatives in the warning.

Bug: tint:1809
Change-Id: If55f162fbd44a1987b573888ca7cc02490f8b05e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117800
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
James Price 2023-01-25 14:10:04 +00:00
parent f629770bcd
commit 58dd079e46
2 changed files with 26 additions and 0 deletions

View File

@ -181,5 +181,26 @@ TEST_F(ResolverDiagnosticControlTest, FunctionAttributeScope) {
89:10 note: code is unreachable)"); 89:10 note: code is unreachable)");
} }
TEST_F(ResolverDiagnosticControlTest, UnrecognizedRuleName_Directive) {
DiagnosticDirective(ast::DiagnosticSeverity::kError,
Expr(Source{{12, 34}}, "chromium_unreachable_cod"));
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(r()->error(),
R"(12:34 warning: unrecognized diagnostic rule 'chromium_unreachable_cod'
Did you mean 'chromium_unreachable_code'?
Possible values: 'chromium_unreachable_code', 'derivative_uniformity')");
}
TEST_F(ResolverDiagnosticControlTest, UnrecognizedRuleName_Attribute) {
auto* attr = DiagnosticAttribute(ast::DiagnosticSeverity::kError,
Expr(Source{{12, 34}}, "chromium_unreachable_cod"));
Func("foo", {}, ty.void_(), {}, utils::Vector{attr});
EXPECT_TRUE(r()->Resolve()) << r()->error();
EXPECT_EQ(r()->error(),
R"(12:34 warning: unrecognized diagnostic rule 'chromium_unreachable_cod'
Did you mean 'chromium_unreachable_code'?
Possible values: 'chromium_unreachable_code', 'derivative_uniformity')");
}
} // namespace } // namespace
} // namespace tint::resolver } // namespace tint::resolver

View File

@ -3069,6 +3069,11 @@ bool Resolver::DiagnosticControl(const ast::DiagnosticControl* control) {
auto rule = ast::ParseDiagnosticRule(rule_name); auto rule = ast::ParseDiagnosticRule(rule_name);
if (rule != ast::DiagnosticRule::kUndefined) { if (rule != ast::DiagnosticRule::kUndefined) {
validator_.DiagnosticFilters().Set(rule, control->severity); validator_.DiagnosticFilters().Set(rule, control->severity);
} else {
std::ostringstream ss;
ss << "unrecognized diagnostic rule '" << rule_name << "'\n";
utils::SuggestAlternatives(rule_name, ast::kDiagnosticRuleStrings, ss);
AddWarning(ss.str(), control->rule_name->source);
} }
return true; return true;
} }