Skip to content

Commit 24ed530

Browse files
committed
fix for descriptor table
1 parent b8644c7 commit 24ed530

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,18 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
240240
DescriptorTable Table;
241241
std::optional<llvm::dxbc::ShaderVisibility> Visibility;
242242

243-
// Iterate as many Clauses as possible
244-
do {
243+
// Iterate as many Clauses as possible, until we hit ')'
244+
while (!peekExpectedToken(TokenKind::pu_r_paren)) {
245245
if (tryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,
246246
TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
247+
// DescriptorTableClause - CBV, SRV, UAV, or Sampler
247248
auto Clause = parseDescriptorTableClause();
248249
if (!Clause.has_value())
249250
return std::nullopt;
250251
Elements.push_back(*Clause);
251252
Table.NumClauses++;
252253
} else if (tryConsumeExpectedToken(TokenKind::kw_visibility)) {
254+
// visibility = SHADER_VISIBILITY
253255
if (Visibility.has_value()) {
254256
reportDiag(diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind;
255257
return std::nullopt;
@@ -262,17 +264,21 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
262264
if (!Visibility.has_value())
263265
return std::nullopt;
264266
}
265-
} while (tryConsumeExpectedToken(TokenKind::pu_comma));
266267

267-
// Fill in optional visibility
268-
if (Visibility.has_value())
269-
Table.Visibility = Visibility.value();
268+
// ',' denotes another element, otherwise, expected to be at ')'
269+
if (!tryConsumeExpectedToken(TokenKind::pu_comma))
270+
break;
271+
}
270272

271273
if (consumeExpectedToken(TokenKind::pu_r_paren,
272274
diag::err_hlsl_unexpected_end_of_params,
273275
/*param of=*/TokenKind::kw_DescriptorTable))
274276
return std::nullopt;
275277

278+
// Fill in optional visibility
279+
if (Visibility.has_value())
280+
Table.Visibility = Visibility.value();
281+
276282
return Table;
277283
}
278284

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,4 +1263,31 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRootElementMissingCommaTest) {
12631263
ASSERT_TRUE(Consumer->isSatisfied());
12641264
}
12651265

1266+
TEST_F(ParseHLSLRootSignatureTest, InvalidDescriptorTableMissingCommaTest) {
1267+
// This test will check that an error is produced when there is a missing
1268+
// comma between parameters
1269+
const llvm::StringLiteral Source = R"cc(
1270+
DescriptorTable(
1271+
CBV(b0)
1272+
visibility = SHADER_VISIBILITY_ALL
1273+
)
1274+
)cc";
1275+
1276+
auto Ctx = createMinimalASTContext();
1277+
StringLiteral *Signature = wrapSource(Ctx, Source);
1278+
1279+
TrivialModuleLoader ModLoader;
1280+
auto PP = createPP(Source, ModLoader);
1281+
1282+
SmallVector<RootElement> Elements;
1283+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
1284+
Signature, *PP);
1285+
1286+
// Test correct diagnostic produced
1287+
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
1288+
ASSERT_TRUE(Parser.parse());
1289+
1290+
ASSERT_TRUE(Consumer->isSatisfied());
1291+
}
1292+
12661293
} // anonymous namespace

0 commit comments

Comments
 (0)