Skip to content

Commit e4c597a

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

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
@@ -497,6 +497,7 @@ bool RootSignatureParser::ParseEnum(
497497
// Handle the edge case when '0' is used to specify None
498498
if (CurTok->Kind == TokenKind::int_literal) {
499499
if (CurTok->NumLiteral.getInt() != 0) {
500+
Diags.Report(CurTok->TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
500501
return true;
501502
}
502503
// Set enum to None equivalent

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,30 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedVisibilityTest) {
589589
ASSERT_TRUE(Consumer->IsSatisfied());
590590
}
591591

592+
TEST_F(ParseHLSLRootSignatureTest, InvalidParseNonZeroFlagTest) {
593+
const llvm::StringLiteral Source = R"cc(
594+
DescriptorTable(
595+
CBV(b0, flags = 3)
596+
)
597+
)cc";
598+
599+
TrivialModuleLoader ModLoader;
600+
auto PP = CreatePP(Source, ModLoader);
601+
auto TokLoc = SourceLocation();
602+
603+
// Test correct diagnostic produced
604+
Consumer->SetExpected(diag::err_hlsl_rootsig_non_zero_flag);
605+
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
606+
607+
SmallVector<hlsl::RootSignatureToken> Tokens;
608+
ASSERT_FALSE(Lexer.Lex(Tokens));
609+
610+
SmallVector<RootElement> Elements;
611+
hlsl::RootSignatureParser Parser(Elements, Tokens, Diags);
612+
613+
ASSERT_TRUE(Parser.Parse());
614+
615+
ASSERT_TRUE(Consumer->IsSatisfied());
616+
}
617+
592618
} // anonymous namespace

0 commit comments

Comments
 (0)