Skip to content

Commit cfe69b1

Browse files
author
Finn Plummer
committed
[HLSL][RootSignature] Make keywords case-insensitive
- from dxc testing, it was shown that keywords could be specified in a case-insensitive manner. the current implementation was case sensitive
1 parent d41aefd commit cfe69b1

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

clang/lib/Lex/LexHLSLRootSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ RootSignatureToken RootSignatureLexer::LexToken() {
9595

9696
// Define a large string switch statement for all the keywords and enums
9797
auto Switch = llvm::StringSwitch<TokenKind>(TokSpelling);
98-
#define KEYWORD(NAME) Switch.Case(#NAME, TokenKind::kw_##NAME);
98+
#define KEYWORD(NAME) Switch.CaseLower(#NAME, TokenKind::kw_##NAME);
9999
#define ENUM(NAME, LIT) Switch.CaseLower(LIT, TokenKind::en_##NAME);
100100
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
101101

clang/unittests/Lex/LexHLSLRootSignatureTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,36 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
120120
CheckTokens(Lexer, Tokens, Expected);
121121
}
122122

123+
TEST_F(LexHLSLRootSignatureTest, ValidCaseInsensitiveKeywordsTest) {
124+
// This test will check that we can lex keywords in an case-insensitive
125+
// manner
126+
const llvm::StringLiteral Source = R"cc(
127+
DeScRiPtOrTaBlE
128+
129+
CBV srv UAV sampler
130+
SPACE visibility FLAGS
131+
numDescriptors OFFSET
132+
)cc";
133+
auto TokLoc = SourceLocation();
134+
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
135+
136+
SmallVector<hlsl::RootSignatureToken> Tokens;
137+
SmallVector<hlsl::TokenKind> Expected = {
138+
hlsl::TokenKind::kw_DescriptorTable,
139+
hlsl::TokenKind::kw_CBV,
140+
hlsl::TokenKind::kw_SRV,
141+
hlsl::TokenKind::kw_UAV,
142+
hlsl::TokenKind::kw_Sampler,
143+
hlsl::TokenKind::kw_space,
144+
hlsl::TokenKind::kw_visibility,
145+
hlsl::TokenKind::kw_flags,
146+
hlsl::TokenKind::kw_numDescriptors,
147+
hlsl::TokenKind::kw_offset,
148+
};
149+
150+
CheckTokens(Lexer, Tokens, Expected);
151+
}
152+
123153
TEST_F(LexHLSLRootSignatureTest, ValidLexPeekTest) {
124154
// This test will check that we the peek api is correctly used
125155
const llvm::StringLiteral Source = R"cc(

0 commit comments

Comments
 (0)