@@ -130,10 +130,10 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
130130TEST_F (ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
131131 const llvm::StringLiteral Source = R"cc(
132132 DescriptorTable(
133- CBV(),
134- SRV(),
135- Sampler(),
136- UAV()
133+ CBV(b0 ),
134+ SRV(space = 3, t42 ),
135+ Sampler(s987, space = +2 ),
136+ UAV(u4294967294 )
137137 ),
138138 DescriptorTable()
139139 )cc" ;
@@ -155,18 +155,34 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
155155 RootElement Elem = Elements[0 ];
156156 ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
157157 ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::CBuffer);
158+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
159+ RegisterType::BReg);
160+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 0u );
161+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 0u );
158162
159163 Elem = Elements[1 ];
160164 ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
161165 ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::SRV);
166+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
167+ RegisterType::TReg);
168+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 42u );
169+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 3u );
162170
163171 Elem = Elements[2 ];
164172 ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
165173 ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::Sampler);
174+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
175+ RegisterType::SReg);
176+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 987u );
177+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 2u );
166178
167179 Elem = Elements[3 ];
168180 ASSERT_TRUE (std::holds_alternative<DescriptorTableClause>(Elem));
169181 ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Type , ClauseType::UAV);
182+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .ViewType ,
183+ RegisterType::UReg);
184+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Register .Number , 4294967294u );
185+ ASSERT_EQ (std::get<DescriptorTableClause>(Elem).Space , 0u );
170186
171187 Elem = Elements[4 ];
172188 ASSERT_TRUE (std::holds_alternative<DescriptorTable>(Elem));
@@ -176,6 +192,32 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
176192 Elem = Elements[5 ];
177193 ASSERT_TRUE (std::holds_alternative<DescriptorTable>(Elem));
178194 ASSERT_EQ (std::get<DescriptorTable>(Elem).NumClauses , 0u );
195+
196+ ASSERT_TRUE (Consumer->isSatisfied ());
197+ }
198+
199+ TEST_F (ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
200+ // This test will checks we can handling trailing commas ','
201+ const llvm::StringLiteral Source = R"cc(
202+ DescriptorTable(
203+ CBV(b0, ),
204+ SRV(t42),
205+ )
206+ )cc" ;
207+
208+ TrivialModuleLoader ModLoader;
209+ auto PP = createPP (Source, ModLoader);
210+ auto TokLoc = SourceLocation ();
211+
212+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
213+ SmallVector<RootElement> Elements;
214+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
215+
216+ // Test no diagnostics produced
217+ Consumer->setNoDiag ();
218+
219+ ASSERT_FALSE (Parser.parse ());
220+
179221 ASSERT_TRUE (Consumer->isSatisfied ());
180222}
181223
@@ -237,6 +279,102 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
237279
238280 // Test correct diagnostic produced - end of stream
239281 Consumer->setExpected (diag::err_expected_after);
282+
283+ ASSERT_TRUE (Parser.parse ());
284+
285+ ASSERT_TRUE (Consumer->isSatisfied ());
286+ }
287+
288+ TEST_F (ParseHLSLRootSignatureTest, InvalidMissingParameterTest) {
289+ // This test will check that the parsing fails due a mandatory
290+ // parameter (register) not being specified
291+ const llvm::StringLiteral Source = R"cc(
292+ DescriptorTable(
293+ CBV()
294+ )
295+ )cc" ;
296+
297+ TrivialModuleLoader ModLoader;
298+ auto PP = createPP (Source, ModLoader);
299+ auto TokLoc = SourceLocation ();
300+
301+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
302+ SmallVector<RootElement> Elements;
303+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
304+
305+ // Test correct diagnostic produced
306+ Consumer->setExpected (diag::err_hlsl_rootsig_missing_param);
307+ ASSERT_TRUE (Parser.parse ());
308+
309+ ASSERT_TRUE (Consumer->isSatisfied ());
310+ }
311+
312+ TEST_F (ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryParameterTest) {
313+ // This test will check that the parsing fails due the same mandatory
314+ // parameter being specified multiple times
315+ const llvm::StringLiteral Source = R"cc(
316+ DescriptorTable(
317+ CBV(b32, b84)
318+ )
319+ )cc" ;
320+
321+ TrivialModuleLoader ModLoader;
322+ auto PP = createPP (Source, ModLoader);
323+ auto TokLoc = SourceLocation ();
324+
325+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
326+ SmallVector<RootElement> Elements;
327+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
328+
329+ // Test correct diagnostic produced
330+ Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
331+ ASSERT_TRUE (Parser.parse ());
332+
333+ ASSERT_TRUE (Consumer->isSatisfied ());
334+ }
335+
336+ TEST_F (ParseHLSLRootSignatureTest, InvalidRepeatedOptionalParameterTest) {
337+ // This test will check that the parsing fails due the same optional
338+ // parameter being specified multiple times
339+ const llvm::StringLiteral Source = R"cc(
340+ DescriptorTable(
341+ CBV(space = 2, space = 0)
342+ )
343+ )cc" ;
344+
345+ TrivialModuleLoader ModLoader;
346+ auto PP = createPP (Source, ModLoader);
347+ auto TokLoc = SourceLocation ();
348+
349+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
350+ SmallVector<RootElement> Elements;
351+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
352+
353+ // Test correct diagnostic produced
354+ Consumer->setExpected (diag::err_hlsl_rootsig_repeat_param);
355+ ASSERT_TRUE (Parser.parse ());
356+
357+ ASSERT_TRUE (Consumer->isSatisfied ());
358+ }
359+
360+ TEST_F (ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
361+ // This test will check that the lexing fails due to an integer overflow
362+ const llvm::StringLiteral Source = R"cc(
363+ DescriptorTable(
364+ CBV(b4294967296)
365+ )
366+ )cc" ;
367+
368+ TrivialModuleLoader ModLoader;
369+ auto PP = createPP (Source, ModLoader);
370+ auto TokLoc = SourceLocation ();
371+
372+ hlsl::RootSignatureLexer Lexer (Source, TokLoc);
373+ SmallVector<RootElement> Elements;
374+ hlsl::RootSignatureParser Parser (Elements, Lexer, *PP);
375+
376+ // Test correct diagnostic produced
377+ Consumer->setExpected (diag::err_hlsl_number_literal_overflow);
240378 ASSERT_TRUE (Parser.parse ());
241379
242380 ASSERT_TRUE (Consumer->isSatisfied ());
0 commit comments