6
6
//
7
7
// ===----------------------------------------------------------------------===//
8
8
9
+ #include " clang/AST/ASTContext.h"
10
+ #include " clang/AST/Expr.h"
9
11
#include " clang/Basic/Diagnostic.h"
10
12
#include " clang/Basic/DiagnosticOptions.h"
11
13
#include " clang/Basic/FileManager.h"
@@ -93,6 +95,22 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
93
95
return PP;
94
96
}
95
97
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
+
96
114
FileSystemOptions FileMgrOpts;
97
115
FileManager FileMgr;
98
116
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
@@ -111,6 +129,9 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
111
129
TEST_F (ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
112
130
const llvm::StringLiteral Source = R"cc( )cc" ;
113
131
132
+ auto Ctx = createMinimalASTContext ();
133
+ StringLiteral *Signature = wrapSource (Ctx, Source);
134
+
114
135
TrivialModuleLoader ModLoader;
115
136
auto PP = createPP (Source, ModLoader);
116
137
auto TokLoc = SourceLocation ();
@@ -146,6 +167,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
146
167
DescriptorTable()
147
168
)cc" ;
148
169
170
+ auto Ctx = createMinimalASTContext ();
171
+ StringLiteral *Signature = wrapSource (Ctx, Source);
172
+
149
173
TrivialModuleLoader ModLoader;
150
174
auto PP = createPP (Source, ModLoader);
151
175
auto TokLoc = SourceLocation ();
@@ -250,6 +274,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
250
274
)
251
275
)cc" ;
252
276
277
+ auto Ctx = createMinimalASTContext ();
278
+ StringLiteral *Signature = wrapSource (Ctx, Source);
279
+
253
280
TrivialModuleLoader ModLoader;
254
281
auto PP = createPP (Source, ModLoader);
255
282
auto TokLoc = SourceLocation ();
@@ -336,6 +363,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
336
363
StaticSampler(s0, mipLODBias = 2147483648),
337
364
)cc" ;
338
365
366
+ auto Ctx = createMinimalASTContext ();
367
+ StringLiteral *Signature = wrapSource (Ctx, Source);
368
+
339
369
TrivialModuleLoader ModLoader;
340
370
auto PP = createPP (Source, ModLoader);
341
371
auto TokLoc = SourceLocation ();
@@ -412,6 +442,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
412
442
DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE))
413
443
)cc" ;
414
444
445
+ auto Ctx = createMinimalASTContext ();
446
+ StringLiteral *Signature = wrapSource (Ctx, Source);
447
+
415
448
TrivialModuleLoader ModLoader;
416
449
auto PP = createPP (Source, ModLoader);
417
450
auto TokLoc = SourceLocation ();
@@ -444,6 +477,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
444
477
)
445
478
)cc" ;
446
479
480
+ auto Ctx = createMinimalASTContext ();
481
+ StringLiteral *Signature = wrapSource (Ctx, Source);
482
+
447
483
TrivialModuleLoader ModLoader;
448
484
auto PP = createPP (Source, ModLoader);
449
485
auto TokLoc = SourceLocation ();
@@ -502,6 +538,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
502
538
)
503
539
)cc" ;
504
540
541
+ auto Ctx = createMinimalASTContext ();
542
+ StringLiteral *Signature = wrapSource (Ctx, Source);
543
+
505
544
TrivialModuleLoader ModLoader;
506
545
auto PP = createPP (Source, ModLoader);
507
546
auto TokLoc = SourceLocation ();
@@ -556,6 +595,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
556
595
CBV(b0, flags = 0),
557
596
)cc" ;
558
597
598
+ auto Ctx = createMinimalASTContext ();
599
+ StringLiteral *Signature = wrapSource (Ctx, Source);
600
+
559
601
TrivialModuleLoader ModLoader;
560
602
auto PP = createPP (Source, ModLoader);
561
603
auto TokLoc = SourceLocation ();
@@ -631,6 +673,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
631
673
)
632
674
)cc" ;
633
675
676
+ auto Ctx = createMinimalASTContext ();
677
+ StringLiteral *Signature = wrapSource (Ctx, Source);
678
+
634
679
TrivialModuleLoader ModLoader;
635
680
auto PP = createPP (Source, ModLoader);
636
681
auto TokLoc = SourceLocation ();
@@ -802,6 +847,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
802
847
space
803
848
)cc" ;
804
849
850
+ auto Ctx = createMinimalASTContext ();
851
+ StringLiteral *Signature = wrapSource (Ctx, Source);
852
+
805
853
TrivialModuleLoader ModLoader;
806
854
auto PP = createPP (Source, ModLoader);
807
855
auto TokLoc = SourceLocation ();
@@ -823,6 +871,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
823
871
notAnIdentifier
824
872
)cc" ;
825
873
874
+ auto Ctx = createMinimalASTContext ();
875
+ StringLiteral *Signature = wrapSource (Ctx, Source);
876
+
826
877
TrivialModuleLoader ModLoader;
827
878
auto PP = createPP (Source, ModLoader);
828
879
auto TokLoc = SourceLocation ();
@@ -844,6 +895,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
844
895
DescriptorTable
845
896
)cc" ;
846
897
898
+ auto Ctx = createMinimalASTContext ();
899
+ StringLiteral *Signature = wrapSource (Ctx, Source);
900
+
847
901
TrivialModuleLoader ModLoader;
848
902
auto PP = createPP (Source, ModLoader);
849
903
auto TokLoc = SourceLocation ();
@@ -870,6 +924,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
870
924
)
871
925
)cc" ;
872
926
927
+ auto Ctx = createMinimalASTContext ();
928
+ StringLiteral *Signature = wrapSource (Ctx, Source);
929
+
873
930
TrivialModuleLoader ModLoader;
874
931
auto PP = createPP (Source, ModLoader);
875
932
auto TokLoc = SourceLocation ();
@@ -893,6 +950,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
893
950
SRV()
894
951
)cc" ;
895
952
953
+ auto Ctx = createMinimalASTContext ();
954
+ StringLiteral *Signature = wrapSource (Ctx, Source);
955
+
896
956
TrivialModuleLoader ModLoader;
897
957
auto PP = createPP (Source, ModLoader);
898
958
auto TokLoc = SourceLocation ();
@@ -916,6 +976,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
916
976
RootConstants(b0)
917
977
)cc" ;
918
978
979
+ auto Ctx = createMinimalASTContext ();
980
+ StringLiteral *Signature = wrapSource (Ctx, Source);
981
+
919
982
TrivialModuleLoader ModLoader;
920
983
auto PP = createPP (Source, ModLoader);
921
984
auto TokLoc = SourceLocation ();
@@ -941,6 +1004,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
941
1004
)
942
1005
)cc" ;
943
1006
1007
+ auto Ctx = createMinimalASTContext ();
1008
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1009
+
944
1010
TrivialModuleLoader ModLoader;
945
1011
auto PP = createPP (Source, ModLoader);
946
1012
auto TokLoc = SourceLocation ();
@@ -964,6 +1030,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
964
1030
RootConstants(num32BitConstants = 32, num32BitConstants = 24)
965
1031
)cc" ;
966
1032
1033
+ auto Ctx = createMinimalASTContext ();
1034
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1035
+
967
1036
TrivialModuleLoader ModLoader;
968
1037
auto PP = createPP (Source, ModLoader);
969
1038
auto TokLoc = SourceLocation ();
@@ -989,6 +1058,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
989
1058
)
990
1059
)cc" ;
991
1060
1061
+ auto Ctx = createMinimalASTContext ();
1062
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1063
+
992
1064
TrivialModuleLoader ModLoader;
993
1065
auto PP = createPP (Source, ModLoader);
994
1066
auto TokLoc = SourceLocation ();
@@ -1016,6 +1088,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
1016
1088
)
1017
1089
)cc" ;
1018
1090
1091
+ auto Ctx = createMinimalASTContext ();
1092
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1093
+
1019
1094
TrivialModuleLoader ModLoader;
1020
1095
auto PP = createPP (Source, ModLoader);
1021
1096
auto TokLoc = SourceLocation ();
@@ -1040,6 +1115,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
1040
1115
)
1041
1116
)cc" ;
1042
1117
1118
+ auto Ctx = createMinimalASTContext ();
1119
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1120
+
1043
1121
TrivialModuleLoader ModLoader;
1044
1122
auto PP = createPP (Source, ModLoader);
1045
1123
auto TokLoc = SourceLocation ();
@@ -1063,6 +1141,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
1063
1141
StaticSampler(s0, mipLODBias = -4294967295)
1064
1142
)cc" ;
1065
1143
1144
+ auto Ctx = createMinimalASTContext ();
1145
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1146
+
1066
1147
TrivialModuleLoader ModLoader;
1067
1148
auto PP = createPP (Source, ModLoader);
1068
1149
auto TokLoc = SourceLocation ();
@@ -1085,6 +1166,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
1085
1166
StaticSampler(s0, mipLODBias = 3.402823467e+38F)
1086
1167
)cc" ;
1087
1168
1169
+ auto Ctx = createMinimalASTContext ();
1170
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1171
+
1088
1172
TrivialModuleLoader ModLoader;
1089
1173
auto PP = createPP (Source, ModLoader);
1090
1174
auto TokLoc = SourceLocation ();
@@ -1107,6 +1191,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
1107
1191
StaticSampler(s0, mipLODBias = -3.402823467e+38F)
1108
1192
)cc" ;
1109
1193
1194
+ auto Ctx = createMinimalASTContext ();
1195
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1196
+
1110
1197
TrivialModuleLoader ModLoader;
1111
1198
auto PP = createPP (Source, ModLoader);
1112
1199
auto TokLoc = SourceLocation ();
@@ -1129,6 +1216,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
1129
1216
StaticSampler(s0, mipLODBias = 1.e+500)
1130
1217
)cc" ;
1131
1218
1219
+ auto Ctx = createMinimalASTContext ();
1220
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1221
+
1132
1222
TrivialModuleLoader ModLoader;
1133
1223
auto PP = createPP (Source, ModLoader);
1134
1224
auto TokLoc = SourceLocation ();
@@ -1151,6 +1241,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
1151
1241
StaticSampler(s0, mipLODBias = 10e-309)
1152
1242
)cc" ;
1153
1243
1244
+ auto Ctx = createMinimalASTContext ();
1245
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1246
+
1154
1247
TrivialModuleLoader ModLoader;
1155
1248
auto PP = createPP (Source, ModLoader);
1156
1249
auto TokLoc = SourceLocation ();
@@ -1176,6 +1269,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
1176
1269
)
1177
1270
)cc" ;
1178
1271
1272
+ auto Ctx = createMinimalASTContext ();
1273
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1274
+
1179
1275
TrivialModuleLoader ModLoader;
1180
1276
auto PP = createPP (Source, ModLoader);
1181
1277
auto TokLoc = SourceLocation ();
0 commit comments