@@ -247,17 +247,19 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
247
247
DescriptorTable Table;
248
248
std::optional<llvm::dxbc::ShaderVisibility> Visibility;
249
249
250
- // Iterate as many Clauses as possible
251
- do {
250
+ // Iterate as many Clauses as possible, until we hit ')'
251
+ while (! peekExpectedToken (TokenKind::pu_r_paren)) {
252
252
if (tryConsumeExpectedToken ({TokenKind::kw_CBV, TokenKind::kw_SRV,
253
253
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
254
+ // DescriptorTableClause - CBV, SRV, UAV, or Sampler
254
255
SourceLocation ElementLoc = getTokenLocation (CurToken);
255
256
auto Clause = parseDescriptorTableClause ();
256
257
if (!Clause.has_value ())
257
258
return std::nullopt;
258
259
Elements.push_back (RootSignatureElement (ElementLoc, *Clause));
259
260
Table.NumClauses ++;
260
261
} else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
262
+ // visibility = SHADER_VISIBILITY
261
263
if (Visibility.has_value ()) {
262
264
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
263
265
return std::nullopt;
@@ -269,16 +271,25 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
269
271
Visibility = parseShaderVisibility ();
270
272
if (!Visibility.has_value ())
271
273
return std::nullopt;
274
+ } else {
275
+ consumeNextToken (); // position to start of invalid token
276
+ reportDiag (diag::err_hlsl_rootsig_invalid_param)
277
+ << /* param of=*/ TokenKind::kw_DescriptorTable;
278
+ return std::nullopt;
272
279
}
273
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
274
280
275
- // Fill in optional visibility
276
- if (Visibility.has_value ())
277
- Table.Visibility = Visibility.value ();
281
+ // ',' denotes another element, otherwise, expected to be at ')'
282
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
283
+ break ;
284
+ }
278
285
279
286
if (consumeExpectedToken (TokenKind::pu_r_paren))
280
287
return std::nullopt;
281
288
289
+ // Fill in optional visibility
290
+ if (Visibility.has_value ())
291
+ Table.Visibility = Visibility.value ();
292
+
282
293
return Table;
283
294
}
284
295
0 commit comments