Skip to content

Commit 51d5304

Browse files
committed
add diagnostic for repeated parametr
1 parent 6f2ad17 commit 51d5304

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,4 +1809,5 @@ def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%
18091809
// HLSL Root Signature Parser Diagnostics
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'">;
1812+
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
18121813
} // end of Parser diagnostics

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ bool RootSignatureParser::ParseOptionalParams(
371371

372372
TokenKind ParamKind = CurTok->Kind;
373373
if (Seen.contains(ParamKind)) {
374+
Diags.Report(CurTok->TokLoc, diag::err_hlsl_rootsig_repeat_param)
375+
<< FormatTokenKinds(ParamKind);
374376
return true;
375377
}
376378
Seen.insert(ParamKind);

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,4 +429,30 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
429429
ASSERT_TRUE(Consumer->IsSatisfied());
430430
}
431431

432+
TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedParamTest) {
433+
const llvm::StringLiteral Source = R"cc(
434+
DescriptorTable(
435+
CBV(b0, numDescriptors = 3, numDescriptors = 1)
436+
)
437+
)cc";
438+
439+
TrivialModuleLoader ModLoader;
440+
auto PP = CreatePP(Source, ModLoader);
441+
auto TokLoc = SourceLocation();
442+
443+
// Test correct diagnostic produced
444+
Consumer->SetExpected(diag::err_hlsl_rootsig_repeat_param);
445+
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
446+
447+
SmallVector<hlsl::RootSignatureToken> Tokens;
448+
ASSERT_FALSE(Lexer.Lex(Tokens));
449+
450+
SmallVector<RootElement> Elements;
451+
hlsl::RootSignatureParser Parser(Elements, Tokens, Diags);
452+
453+
ASSERT_TRUE(Parser.Parse());
454+
455+
ASSERT_TRUE(Consumer->IsSatisfied());
456+
}
457+
432458
} // anonymous namespace

0 commit comments

Comments
 (0)