Skip to content

Commit 24f0a9e

Browse files
committed
add diagnostic for non-zero int literal as flag
1 parent 6775f3d commit 24f0a9e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,4 +1810,6 @@ def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%
18101810
def err_hlsl_rootsig_unexpected_eos : Error<"unexpected end to token stream">;
18111811
def err_hlsl_rootsig_unexpected_token_kind : Error<"expected the %select{following|one of the following}0 token kinds '%1'">;
18121812
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
1813+
def err_hlsl_rootsig_non_zero_flag : Error<"specified a non-zero integer as a flag">;
1814+
18131815
} // end of Parser diagnostics

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ bool RootSignatureParser::ParseEnum(
476476
// Handle the edge case when '0' is used to specify None
477477
if (CurTok->Kind == TokenKind::int_literal) {
478478
if (CurTok->NumLiteral.getInt() != 0) {
479+
Diags.Report(CurTok->TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
479480
return true;
480481
}
481482
// Set enum to None equivalent

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,4 +511,30 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedVisibilityTest) {
511511
ASSERT_TRUE(Consumer->IsSatisfied());
512512
}
513513

514+
TEST_F(ParseHLSLRootSignatureTest, InvalidParseNonZeroFlagTest) {
515+
const llvm::StringLiteral Source = R"cc(
516+
DescriptorTable(
517+
CBV(b0, flags = 3)
518+
)
519+
)cc";
520+
521+
TrivialModuleLoader ModLoader;
522+
auto PP = CreatePP(Source, ModLoader);
523+
auto TokLoc = SourceLocation();
524+
525+
// Test correct diagnostic produced
526+
Consumer->SetExpected(diag::err_hlsl_rootsig_non_zero_flag);
527+
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
528+
529+
SmallVector<hlsl::RootSignatureToken> Tokens;
530+
ASSERT_FALSE(Lexer.Lex(Tokens));
531+
532+
SmallVector<RootElement> Elements;
533+
hlsl::RootSignatureParser Parser(Elements, Tokens, Diags);
534+
535+
ASSERT_TRUE(Parser.Parse());
536+
537+
ASSERT_TRUE(Consumer->IsSatisfied());
538+
}
539+
514540
} // anonymous namespace

0 commit comments

Comments
 (0)