Skip to content

Commit d037590

Browse files
committed
add diagnostic for non-zero int literal as flag
1 parent 3c928d5 commit d037590

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
@@ -469,6 +469,7 @@ bool RootSignatureParser::ParseEnum(
469469
// Handle the edge case when '0' is used to specify None
470470
if (CurTok->Kind == TokenKind::int_literal) {
471471
if (CurTok->NumLiteral.getInt() != 0) {
472+
Diags.Report(CurTok->TokLoc, diag::err_hlsl_rootsig_non_zero_flag);
472473
return true;
473474
}
474475
// Set enum to None equivalent

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,30 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedVisibilityTest) {
538538
ASSERT_TRUE(Consumer->IsSatisfied());
539539
}
540540

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

0 commit comments

Comments
 (0)