Skip to content

Commit a9d4d56

Browse files
committed
add diagnostic for non-zero int literal as flag
1 parent 1f75248 commit a9d4d56

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,4 +1809,6 @@ def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%
18091809
// HLSL Root Signature Parser Diagnostics
18101810
def err_hlsl_rootsig_unexpected_token_kind : Error<"expected %select{the following|one of the following}0 token kind%select{|s}0: %1">;
18111811
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
1812+
def err_hlsl_rootsig_non_zero_flag : Error<"specified a non-zero integer as a flag">;
1813+
18121814
} // end of Parser diagnostics

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@ bool RootSignatureParser::ParseEnum(
470470
return true;
471471

472472
// Handle the edge case when '0' is used to specify None
473-
if (CurTok->Kind == TokenKind::int_literal) {
474-
if (CurTok->NumLiteral.getInt() != 0) {
473+
if (CurToken.Kind == TokenKind::int_literal) {
474+
if (CurToken.NumLiteral.getInt() != 0) {
475+
Diags.Report(CurToken.TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
475476
return true;
476477
}
477478
// Set enum to None equivalent

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,4 +541,26 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedVisibilityTest) {
541541
ASSERT_TRUE(Consumer->IsSatisfied());
542542
}
543543

544+
TEST_F(ParseHLSLRootSignatureTest, InvalidParseNonZeroFlagTest) {
545+
const llvm::StringLiteral Source = R"cc(
546+
DescriptorTable(
547+
CBV(b0, flags = 3)
548+
)
549+
)cc";
550+
551+
TrivialModuleLoader ModLoader;
552+
auto PP = CreatePP(Source, ModLoader);
553+
auto TokLoc = SourceLocation();
554+
555+
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
556+
SmallVector<RootElement> Elements;
557+
hlsl::RootSignatureParser Parser(Elements, Lexer, Diags);
558+
559+
// Test correct diagnostic produced
560+
Consumer->SetExpected(diag::err_hlsl_rootsig_non_zero_flag);
561+
ASSERT_TRUE(Parser.Parse());
562+
563+
ASSERT_TRUE(Consumer->IsSatisfied());
564+
}
565+
544566
} // anonymous namespace

0 commit comments

Comments
 (0)