66//
77// ===----------------------------------------------------------------------===//
88
9+ #include " clang/AST/ASTContext.h"
10+ #include " clang/AST/Expr.h"
911#include " clang/Basic/Diagnostic.h"
1012#include " clang/Basic/DiagnosticOptions.h"
1113#include " clang/Basic/FileManager.h"
@@ -93,6 +95,22 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
9395 return PP;
9496 }
9597
98+ std::unique_ptr<ASTContext> createMinimalASTContext () {
99+ IdentifierTable Idents (LangOpts);
100+ SelectorTable Selectors;
101+ Builtin::Context Builtins;
102+
103+ return std::make_unique<ASTContext>(LangOpts, SourceMgr, Idents, Selectors,
104+ Builtins, TU_Complete);
105+ }
106+
107+ StringLiteral *wrapSource (std::unique_ptr<ASTContext> &Ctx,
108+ StringRef Source) {
109+ SourceLocation Locs[1 ] = {SourceLocation ()};
110+ return StringLiteral::Create (*Ctx, Source, StringLiteralKind::Unevaluated,
111+ false , Ctx->VoidTy , Locs);
112+ }
113+
96114 FileSystemOptions FileMgrOpts;
97115 FileManager FileMgr;
98116 IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
@@ -111,6 +129,9 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
111129TEST_F (ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
112130 const llvm::StringLiteral Source = R"cc( )cc" ;
113131
132+ auto Ctx = createMinimalASTContext ();
133+ StringLiteral *Signature = wrapSource (Ctx, Source);
134+
114135 TrivialModuleLoader ModLoader;
115136 auto PP = createPP (Source, ModLoader);
116137 auto TokLoc = SourceLocation ();
@@ -146,6 +167,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
146167 DescriptorTable()
147168 )cc" ;
148169
170+ auto Ctx = createMinimalASTContext ();
171+ StringLiteral *Signature = wrapSource (Ctx, Source);
172+
149173 TrivialModuleLoader ModLoader;
150174 auto PP = createPP (Source, ModLoader);
151175 auto TokLoc = SourceLocation ();
@@ -250,6 +274,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
250274 )
251275 )cc" ;
252276
277+ auto Ctx = createMinimalASTContext ();
278+ StringLiteral *Signature = wrapSource (Ctx, Source);
279+
253280 TrivialModuleLoader ModLoader;
254281 auto PP = createPP (Source, ModLoader);
255282 auto TokLoc = SourceLocation ();
@@ -336,6 +363,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
336363 StaticSampler(s0, mipLODBias = 2147483648),
337364 )cc" ;
338365
366+ auto Ctx = createMinimalASTContext ();
367+ StringLiteral *Signature = wrapSource (Ctx, Source);
368+
339369 TrivialModuleLoader ModLoader;
340370 auto PP = createPP (Source, ModLoader);
341371 auto TokLoc = SourceLocation ();
@@ -412,6 +442,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
412442 DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE))
413443 )cc" ;
414444
445+ auto Ctx = createMinimalASTContext ();
446+ StringLiteral *Signature = wrapSource (Ctx, Source);
447+
415448 TrivialModuleLoader ModLoader;
416449 auto PP = createPP (Source, ModLoader);
417450 auto TokLoc = SourceLocation ();
@@ -444,6 +477,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
444477 )
445478 )cc" ;
446479
480+ auto Ctx = createMinimalASTContext ();
481+ StringLiteral *Signature = wrapSource (Ctx, Source);
482+
447483 TrivialModuleLoader ModLoader;
448484 auto PP = createPP (Source, ModLoader);
449485 auto TokLoc = SourceLocation ();
@@ -502,6 +538,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
502538 )
503539 )cc" ;
504540
541+ auto Ctx = createMinimalASTContext ();
542+ StringLiteral *Signature = wrapSource (Ctx, Source);
543+
505544 TrivialModuleLoader ModLoader;
506545 auto PP = createPP (Source, ModLoader);
507546 auto TokLoc = SourceLocation ();
@@ -556,6 +595,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
556595 CBV(b0, flags = 0),
557596 )cc" ;
558597
598+ auto Ctx = createMinimalASTContext ();
599+ StringLiteral *Signature = wrapSource (Ctx, Source);
600+
559601 TrivialModuleLoader ModLoader;
560602 auto PP = createPP (Source, ModLoader);
561603 auto TokLoc = SourceLocation ();
@@ -631,6 +673,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
631673 )
632674 )cc" ;
633675
676+ auto Ctx = createMinimalASTContext ();
677+ StringLiteral *Signature = wrapSource (Ctx, Source);
678+
634679 TrivialModuleLoader ModLoader;
635680 auto PP = createPP (Source, ModLoader);
636681 auto TokLoc = SourceLocation ();
@@ -802,6 +847,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
802847 space
803848 )cc" ;
804849
850+ auto Ctx = createMinimalASTContext ();
851+ StringLiteral *Signature = wrapSource (Ctx, Source);
852+
805853 TrivialModuleLoader ModLoader;
806854 auto PP = createPP (Source, ModLoader);
807855 auto TokLoc = SourceLocation ();
@@ -823,6 +871,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
823871 notAnIdentifier
824872 )cc" ;
825873
874+ auto Ctx = createMinimalASTContext ();
875+ StringLiteral *Signature = wrapSource (Ctx, Source);
876+
826877 TrivialModuleLoader ModLoader;
827878 auto PP = createPP (Source, ModLoader);
828879 auto TokLoc = SourceLocation ();
@@ -844,6 +895,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
844895 DescriptorTable
845896 )cc" ;
846897
898+ auto Ctx = createMinimalASTContext ();
899+ StringLiteral *Signature = wrapSource (Ctx, Source);
900+
847901 TrivialModuleLoader ModLoader;
848902 auto PP = createPP (Source, ModLoader);
849903 auto TokLoc = SourceLocation ();
@@ -870,6 +924,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
870924 )
871925 )cc" ;
872926
927+ auto Ctx = createMinimalASTContext ();
928+ StringLiteral *Signature = wrapSource (Ctx, Source);
929+
873930 TrivialModuleLoader ModLoader;
874931 auto PP = createPP (Source, ModLoader);
875932 auto TokLoc = SourceLocation ();
@@ -893,6 +950,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
893950 SRV()
894951 )cc" ;
895952
953+ auto Ctx = createMinimalASTContext ();
954+ StringLiteral *Signature = wrapSource (Ctx, Source);
955+
896956 TrivialModuleLoader ModLoader;
897957 auto PP = createPP (Source, ModLoader);
898958 auto TokLoc = SourceLocation ();
@@ -916,6 +976,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
916976 RootConstants(b0)
917977 )cc" ;
918978
979+ auto Ctx = createMinimalASTContext ();
980+ StringLiteral *Signature = wrapSource (Ctx, Source);
981+
919982 TrivialModuleLoader ModLoader;
920983 auto PP = createPP (Source, ModLoader);
921984 auto TokLoc = SourceLocation ();
@@ -941,6 +1004,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
9411004 )
9421005 )cc" ;
9431006
1007+ auto Ctx = createMinimalASTContext ();
1008+ StringLiteral *Signature = wrapSource (Ctx, Source);
1009+
9441010 TrivialModuleLoader ModLoader;
9451011 auto PP = createPP (Source, ModLoader);
9461012 auto TokLoc = SourceLocation ();
@@ -964,6 +1030,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
9641030 RootConstants(num32BitConstants = 32, num32BitConstants = 24)
9651031 )cc" ;
9661032
1033+ auto Ctx = createMinimalASTContext ();
1034+ StringLiteral *Signature = wrapSource (Ctx, Source);
1035+
9671036 TrivialModuleLoader ModLoader;
9681037 auto PP = createPP (Source, ModLoader);
9691038 auto TokLoc = SourceLocation ();
@@ -989,6 +1058,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
9891058 )
9901059 )cc" ;
9911060
1061+ auto Ctx = createMinimalASTContext ();
1062+ StringLiteral *Signature = wrapSource (Ctx, Source);
1063+
9921064 TrivialModuleLoader ModLoader;
9931065 auto PP = createPP (Source, ModLoader);
9941066 auto TokLoc = SourceLocation ();
@@ -1016,6 +1088,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
10161088 )
10171089 )cc" ;
10181090
1091+ auto Ctx = createMinimalASTContext ();
1092+ StringLiteral *Signature = wrapSource (Ctx, Source);
1093+
10191094 TrivialModuleLoader ModLoader;
10201095 auto PP = createPP (Source, ModLoader);
10211096 auto TokLoc = SourceLocation ();
@@ -1040,6 +1115,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
10401115 )
10411116 )cc" ;
10421117
1118+ auto Ctx = createMinimalASTContext ();
1119+ StringLiteral *Signature = wrapSource (Ctx, Source);
1120+
10431121 TrivialModuleLoader ModLoader;
10441122 auto PP = createPP (Source, ModLoader);
10451123 auto TokLoc = SourceLocation ();
@@ -1063,6 +1141,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
10631141 StaticSampler(s0, mipLODBias = -4294967295)
10641142 )cc" ;
10651143
1144+ auto Ctx = createMinimalASTContext ();
1145+ StringLiteral *Signature = wrapSource (Ctx, Source);
1146+
10661147 TrivialModuleLoader ModLoader;
10671148 auto PP = createPP (Source, ModLoader);
10681149 auto TokLoc = SourceLocation ();
@@ -1085,6 +1166,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
10851166 StaticSampler(s0, mipLODBias = 3.402823467e+38F)
10861167 )cc" ;
10871168
1169+ auto Ctx = createMinimalASTContext ();
1170+ StringLiteral *Signature = wrapSource (Ctx, Source);
1171+
10881172 TrivialModuleLoader ModLoader;
10891173 auto PP = createPP (Source, ModLoader);
10901174 auto TokLoc = SourceLocation ();
@@ -1107,6 +1191,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
11071191 StaticSampler(s0, mipLODBias = -3.402823467e+38F)
11081192 )cc" ;
11091193
1194+ auto Ctx = createMinimalASTContext ();
1195+ StringLiteral *Signature = wrapSource (Ctx, Source);
1196+
11101197 TrivialModuleLoader ModLoader;
11111198 auto PP = createPP (Source, ModLoader);
11121199 auto TokLoc = SourceLocation ();
@@ -1129,6 +1216,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
11291216 StaticSampler(s0, mipLODBias = 1.e+500)
11301217 )cc" ;
11311218
1219+ auto Ctx = createMinimalASTContext ();
1220+ StringLiteral *Signature = wrapSource (Ctx, Source);
1221+
11321222 TrivialModuleLoader ModLoader;
11331223 auto PP = createPP (Source, ModLoader);
11341224 auto TokLoc = SourceLocation ();
@@ -1151,6 +1241,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
11511241 StaticSampler(s0, mipLODBias = 10e-309)
11521242 )cc" ;
11531243
1244+ auto Ctx = createMinimalASTContext ();
1245+ StringLiteral *Signature = wrapSource (Ctx, Source);
1246+
11541247 TrivialModuleLoader ModLoader;
11551248 auto PP = createPP (Source, ModLoader);
11561249 auto TokLoc = SourceLocation ();
@@ -1176,6 +1269,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
11761269 )
11771270 )cc" ;
11781271
1272+ auto Ctx = createMinimalASTContext ();
1273+ StringLiteral *Signature = wrapSource (Ctx, Source);
1274+
11791275 TrivialModuleLoader ModLoader;
11801276 auto PP = createPP (Source, ModLoader);
11811277 auto TokLoc = SourceLocation ();
0 commit comments