Skip to content

Commit 83c4cb3

Browse files
inbelicFinn Plummer
andauthored
[HLSL][RootSignature] Make Root Signature lexer keywords case-insensitive (#132967)
From the corrections to the Root Signature specification here: llvm/wg-hlsl#192. It was denoted that keywords are also case-insensitive in DXC. This pr adjusts the lexer to adhere to the updated spec. We also have a NFC to add a missing license to a file while in the area. --------- Co-authored-by: Finn Plummer <[email protected]>
1 parent 812e02a commit 83c4cb3

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

clang/lib/Lex/LexHLSLRootSignature.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//=== LexHLSLRootSignature.cpp - Lex Root Signature -----------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
19
#include "clang/Lex/LexHLSLRootSignature.h"
210

311
namespace clang {
@@ -87,7 +95,7 @@ RootSignatureToken RootSignatureLexer::LexToken() {
8795

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

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)