@@ -209,10 +209,13 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() {
209
209
}
210
210
Descriptor.setDefaultFlags (Version);
211
211
212
- auto Params = parseRootDescriptorParams (ExpectedReg);
212
+ auto Params = parseRootDescriptorParams (DescriptorKind, ExpectedReg);
213
213
if (!Params.has_value ())
214
214
return std::nullopt;
215
215
216
+ if (consumeExpectedToken (TokenKind::pu_r_paren))
217
+ return std::nullopt;
218
+
216
219
// Check mandatory parameters were provided
217
220
if (!Params->Reg .has_value ()) {
218
221
reportDiag (diag::err_hlsl_rootsig_missing_param) << ExpectedReg;
@@ -231,9 +234,6 @@ std::optional<RootDescriptor> RootSignatureParser::parseRootDescriptor() {
231
234
if (Params->Flags .has_value ())
232
235
Descriptor.Flags = Params->Flags .value ();
233
236
234
- if (consumeExpectedToken (TokenKind::pu_r_paren))
235
- return std::nullopt;
236
-
237
237
return Descriptor;
238
238
}
239
239
@@ -503,14 +503,15 @@ RootSignatureParser::parseRootConstantParams() {
503
503
}
504
504
505
505
std::optional<RootSignatureParser::ParsedRootDescriptorParams>
506
- RootSignatureParser::parseRootDescriptorParams (TokenKind RegType) {
506
+ RootSignatureParser::parseRootDescriptorParams (TokenKind DescType,
507
+ TokenKind RegType) {
507
508
assert (CurToken.TokKind == TokenKind::pu_l_paren &&
508
509
" Expects to only be invoked starting at given token" );
509
510
510
511
ParsedRootDescriptorParams Params;
511
- do {
512
- // ( `b` | `t` | `u`) POS_INT
512
+ while (!peekExpectedToken (TokenKind::pu_r_paren)) {
513
513
if (tryConsumeExpectedToken (RegType)) {
514
+ // ( `b` | `t` | `u`) POS_INT
514
515
if (Params.Reg .has_value ()) {
515
516
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
516
517
return std::nullopt;
@@ -519,10 +520,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
519
520
if (!Reg.has_value ())
520
521
return std::nullopt;
521
522
Params.Reg = Reg;
522
- }
523
-
524
- // `space` `=` POS_INT
525
- if (tryConsumeExpectedToken (TokenKind::kw_space)) {
523
+ } else if (tryConsumeExpectedToken (TokenKind::kw_space)) {
524
+ // `space` `=` POS_INT
526
525
if (Params.Space .has_value ()) {
527
526
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
528
527
return std::nullopt;
@@ -535,10 +534,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
535
534
if (!Space.has_value ())
536
535
return std::nullopt;
537
536
Params.Space = Space;
538
- }
539
-
540
- // `visibility` `=` SHADER_VISIBILITY
541
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
537
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
538
+ // `visibility` `=` SHADER_VISIBILITY
542
539
if (Params.Visibility .has_value ()) {
543
540
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
544
541
return std::nullopt;
@@ -551,10 +548,8 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
551
548
if (!Visibility.has_value ())
552
549
return std::nullopt;
553
550
Params.Visibility = Visibility;
554
- }
555
-
556
- // `flags` `=` ROOT_DESCRIPTOR_FLAGS
557
- if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
551
+ } else if (tryConsumeExpectedToken (TokenKind::kw_flags)) {
552
+ // `flags` `=` ROOT_DESCRIPTOR_FLAGS
558
553
if (Params.Flags .has_value ()) {
559
554
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
560
555
return std::nullopt;
@@ -567,8 +562,16 @@ RootSignatureParser::parseRootDescriptorParams(TokenKind RegType) {
567
562
if (!Flags.has_value ())
568
563
return std::nullopt;
569
564
Params.Flags = Flags;
565
+ } else {
566
+ consumeNextToken (); // position to start of invalid token
567
+ reportDiag (diag::err_hlsl_rootsig_invalid_param) << /* param of=*/ DescType;
568
+ return std::nullopt;
570
569
}
571
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
570
+
571
+ // ',' denotes another element, otherwise, expected to be at ')'
572
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
573
+ break ;
574
+ }
572
575
573
576
return Params;
574
577
}
0 commit comments