Skip to content

Commit 5175c32

Browse files
committed
add diagnostic for repeated parametr
1 parent b160219 commit 5175c32

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,4 +1808,5 @@ def err_hlsl_packoffset_invalid_reg : Error<"invalid resource class specifier '%
18081808

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">;
1811+
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
18111812
} // end of Parser diagnostics

clang/lib/Parse/ParseHLSLRootSignature.cpp

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

367367
TokenKind ParamKind = CurToken.Kind;
368368
if (Seen.contains(ParamKind)) {
369+
Diags.Report(CurToken.TokLoc, diag::err_hlsl_rootsig_repeat_param)
370+
<< FormatTokenKinds(ParamKind);
369371
return true;
370372
}
371373
Seen.insert(ParamKind);

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,26 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
467467
ASSERT_TRUE(Consumer->IsSatisfied());
468468
}
469469

470+
TEST_F(ParseHLSLRootSignatureTest, InvalidParseRepeatedParamTest) {
471+
const llvm::StringLiteral Source = R"cc(
472+
DescriptorTable(
473+
CBV(b0, numDescriptors = 3, numDescriptors = 1)
474+
)
475+
)cc";
476+
477+
TrivialModuleLoader ModLoader;
478+
auto PP = CreatePP(Source, ModLoader);
479+
auto TokLoc = SourceLocation();
480+
481+
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
482+
SmallVector<RootElement> Elements;
483+
hlsl::RootSignatureParser Parser(Elements, Lexer, Diags);
484+
485+
// Test correct diagnostic produced
486+
Consumer->SetExpected(diag::err_hlsl_rootsig_repeat_param);
487+
ASSERT_TRUE(Parser.Parse());
488+
489+
ASSERT_TRUE(Consumer->IsSatisfied());
490+
}
491+
470492
} // anonymous namespace

0 commit comments

Comments
 (0)