Skip to content

Commit 743f8ac

Browse files
committed
review: correctly exit the table scope before reporting more errors
1 parent 7ec7e32 commit 743f8ac

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,13 @@ class RootSignatureParser {
206206
bool skipUntilExpectedToken(RootSignatureToken::Kind Expected);
207207
bool skipUntilExpectedToken(ArrayRef<RootSignatureToken::Kind> Expected);
208208

209+
/// Consume tokens until we reach a closing right paren, ')', or, until we
210+
/// have reached the end of the stream. This will place the current token
211+
/// to be the end of stream or the right paren.
212+
///
213+
/// Returns true if it is closed before the end of stream.
214+
bool skipUntilClosedParens(uint32_t NumParens = 1);
215+
209216
/// Convert the token's offset in the signature string to its SourceLocation
210217
///
211218
/// This allows to currently retrieve the location for multi-token

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool RootSignatureParser::parse() {
6262
HadLocalError = true;
6363
// We are within a DescriptorTable, we will do our best to recover
6464
// by skipping until we encounter the expected closing ')'.
65-
skipUntilExpectedToken(TokenKind::pu_r_paren);
65+
skipUntilClosedParens();
6666
consumeNextToken();
6767
}
6868
} else if (tryConsumeExpectedToken(
@@ -1418,6 +1418,24 @@ bool RootSignatureParser::skipUntilExpectedToken(
14181418
return true;
14191419
}
14201420

1421+
bool RootSignatureParser::skipUntilClosedParens(uint32_t NumParens) {
1422+
TokenKind ParenKinds[] = {
1423+
TokenKind::pu_l_paren,
1424+
TokenKind::pu_r_paren,
1425+
};
1426+
while (skipUntilExpectedToken(ParenKinds)) {
1427+
consumeNextToken();
1428+
if (CurToken.TokKind == TokenKind::pu_r_paren)
1429+
NumParens--;
1430+
else
1431+
NumParens++;
1432+
if (NumParens == 0)
1433+
return true;
1434+
}
1435+
1436+
return false;
1437+
}
1438+
14211439
SourceLocation RootSignatureParser::getTokenLocation(RootSignatureToken Tok) {
14221440
return Signature->getLocationOfByte(Tok.LocOffset, PP.getSourceManager(),
14231441
PP.getLangOpts(), PP.getTargetInfo());

clang/test/SemaHLSL/RootSignature-err.hlsl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,16 @@ void multiple_errors() {}
141141
// expected-error@+1 {{invalid parameter of SRV}}
142142
[RootSignature(DemoGranularityRootSignature)]
143143
void granularity_errors() {}
144+
145+
#define TestTableScope \
146+
"DescriptorTable( " \
147+
" UAV(u0, reported_diag), " \
148+
" SRV(t0, skipped_diag), " \
149+
" Sampler(s0, skipped_diag), " \
150+
")," \
151+
"CBV(s0, reported_diag)"
152+
153+
// expected-error@+2 {{invalid parameter of UAV}}
154+
// expected-error@+1 {{invalid parameter of CBV}}
155+
[RootSignature(TestTableScope)]
156+
void recover_scope_errors() {}

0 commit comments

Comments
 (0)