Skip to content

Commit 5054e7a

Browse files
committed
nfc: improve error message for non-zero flag diagnostic
- we shouldn't pass in a string to the diagnostic, instead we should define the string properly and provide better context
1 parent b471274 commit 5054e7a

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,5 +1842,6 @@ def err_hlsl_unexpected_end_of_params
18421842
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
18431843
def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory parameter '%0'">;
18441844
def err_hlsl_number_literal_overflow : Error<"integer literal is too large to be represented as a 32-bit %select{signed |}0 integer type">;
1845+
def err_hlsl_rootsig_non_zero_flag : Error<"non-zero integer literal specified for flag value">;
18451846

18461847
} // end of Parser diagnostics

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::optional<RootFlags> RootSignatureParser::parseRootFlags() {
7676
// Handle the edge-case of '0' to specify no flags set
7777
if (tryConsumeExpectedToken(TokenKind::int_literal)) {
7878
if (!verifyZeroFlag()) {
79-
getDiags().Report(CurToken.TokLoc, diag::err_expected) << "'0'";
79+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
8080
return std::nullopt;
8181
}
8282
} else {
@@ -538,7 +538,7 @@ RootSignatureParser::parseDescriptorRangeFlags() {
538538
// Handle the edge-case of '0' to specify no flags set
539539
if (tryConsumeExpectedToken(TokenKind::int_literal)) {
540540
if (!verifyZeroFlag()) {
541-
getDiags().Report(CurToken.TokLoc, diag::err_expected) << "'0'";
541+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
542542
return std::nullopt;
543543
}
544544
return DescriptorRangeFlags::None;

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
546546
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
547547

548548
// Test correct diagnostic produced
549-
Consumer->setExpected(diag::err_expected);
549+
Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);
550550
ASSERT_TRUE(Parser.parse());
551551

552552
ASSERT_TRUE(Consumer->isSatisfied());

0 commit comments

Comments
 (0)