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"
@@ -91,6 +93,22 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
91
93
return PP;
92
94
}
93
95
96
+ std::unique_ptr<ASTContext> createMinimalASTContext () {
97
+ IdentifierTable Idents (LangOpts);
98
+ SelectorTable Selectors;
99
+ Builtin::Context Builtins;
100
+
101
+ return std::make_unique<ASTContext>(LangOpts, SourceMgr, Idents, Selectors,
102
+ Builtins, TU_Complete);
103
+ }
104
+
105
+ StringLiteral *wrapSource (std::unique_ptr<ASTContext> &Ctx,
106
+ StringRef Source) {
107
+ SourceLocation Locs[1 ] = {SourceLocation ()};
108
+ return StringLiteral::Create (*Ctx, Source, StringLiteralKind::Unevaluated,
109
+ false , Ctx->VoidTy , Locs);
110
+ }
111
+
94
112
FileSystemOptions FileMgrOpts;
95
113
FileManager FileMgr;
96
114
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
@@ -109,6 +127,9 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
109
127
TEST_F (ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
110
128
const llvm::StringLiteral Source = R"cc( )cc" ;
111
129
130
+ auto Ctx = createMinimalASTContext ();
131
+ StringLiteral *Signature = wrapSource (Ctx, Source);
132
+
112
133
TrivialModuleLoader ModLoader;
113
134
auto PP = createPP (Source, ModLoader);
114
135
auto TokLoc = SourceLocation ();
@@ -143,6 +164,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
143
164
DescriptorTable()
144
165
)cc" ;
145
166
167
+ auto Ctx = createMinimalASTContext ();
168
+ StringLiteral *Signature = wrapSource (Ctx, Source);
169
+
146
170
TrivialModuleLoader ModLoader;
147
171
auto PP = createPP (Source, ModLoader);
148
172
auto TokLoc = SourceLocation ();
@@ -246,6 +270,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
246
270
)
247
271
)cc" ;
248
272
273
+ auto Ctx = createMinimalASTContext ();
274
+ StringLiteral *Signature = wrapSource (Ctx, Source);
275
+
249
276
TrivialModuleLoader ModLoader;
250
277
auto PP = createPP (Source, ModLoader);
251
278
auto TokLoc = SourceLocation ();
@@ -331,6 +358,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
331
358
StaticSampler(s0, mipLODBias = 2147483648),
332
359
)cc" ;
333
360
361
+ auto Ctx = createMinimalASTContext ();
362
+ StringLiteral *Signature = wrapSource (Ctx, Source);
363
+
334
364
TrivialModuleLoader ModLoader;
335
365
auto PP = createPP (Source, ModLoader);
336
366
auto TokLoc = SourceLocation ();
@@ -406,6 +436,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
406
436
DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE))
407
437
)cc" ;
408
438
439
+ auto Ctx = createMinimalASTContext ();
440
+ StringLiteral *Signature = wrapSource (Ctx, Source);
441
+
409
442
TrivialModuleLoader ModLoader;
410
443
auto PP = createPP (Source, ModLoader);
411
444
auto TokLoc = SourceLocation ();
@@ -437,6 +470,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
437
470
)
438
471
)cc" ;
439
472
473
+ auto Ctx = createMinimalASTContext ();
474
+ StringLiteral *Signature = wrapSource (Ctx, Source);
475
+
440
476
TrivialModuleLoader ModLoader;
441
477
auto PP = createPP (Source, ModLoader);
442
478
auto TokLoc = SourceLocation ();
@@ -494,6 +530,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
494
530
)
495
531
)cc" ;
496
532
533
+ auto Ctx = createMinimalASTContext ();
534
+ StringLiteral *Signature = wrapSource (Ctx, Source);
535
+
497
536
TrivialModuleLoader ModLoader;
498
537
auto PP = createPP (Source, ModLoader);
499
538
auto TokLoc = SourceLocation ();
@@ -547,6 +586,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
547
586
CBV(b0, flags = 0),
548
587
)cc" ;
549
588
589
+ auto Ctx = createMinimalASTContext ();
590
+ StringLiteral *Signature = wrapSource (Ctx, Source);
591
+
550
592
TrivialModuleLoader ModLoader;
551
593
auto PP = createPP (Source, ModLoader);
552
594
auto TokLoc = SourceLocation ();
@@ -621,6 +663,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
621
663
)
622
664
)cc" ;
623
665
666
+ auto Ctx = createMinimalASTContext ();
667
+ StringLiteral *Signature = wrapSource (Ctx, Source);
668
+
624
669
TrivialModuleLoader ModLoader;
625
670
auto PP = createPP (Source, ModLoader);
626
671
auto TokLoc = SourceLocation ();
@@ -645,6 +690,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
645
690
space
646
691
)cc" ;
647
692
693
+ auto Ctx = createMinimalASTContext ();
694
+ StringLiteral *Signature = wrapSource (Ctx, Source);
695
+
648
696
TrivialModuleLoader ModLoader;
649
697
auto PP = createPP (Source, ModLoader);
650
698
auto TokLoc = SourceLocation ();
@@ -665,6 +713,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
665
713
notAnIdentifier
666
714
)cc" ;
667
715
716
+ auto Ctx = createMinimalASTContext ();
717
+ StringLiteral *Signature = wrapSource (Ctx, Source);
718
+
668
719
TrivialModuleLoader ModLoader;
669
720
auto PP = createPP (Source, ModLoader);
670
721
auto TokLoc = SourceLocation ();
@@ -685,6 +736,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
685
736
DescriptorTable
686
737
)cc" ;
687
738
739
+ auto Ctx = createMinimalASTContext ();
740
+ StringLiteral *Signature = wrapSource (Ctx, Source);
741
+
688
742
TrivialModuleLoader ModLoader;
689
743
auto PP = createPP (Source, ModLoader);
690
744
auto TokLoc = SourceLocation ();
@@ -710,6 +764,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
710
764
)
711
765
)cc" ;
712
766
767
+ auto Ctx = createMinimalASTContext ();
768
+ StringLiteral *Signature = wrapSource (Ctx, Source);
769
+
713
770
TrivialModuleLoader ModLoader;
714
771
auto PP = createPP (Source, ModLoader);
715
772
auto TokLoc = SourceLocation ();
@@ -732,6 +789,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
732
789
SRV()
733
790
)cc" ;
734
791
792
+ auto Ctx = createMinimalASTContext ();
793
+ StringLiteral *Signature = wrapSource (Ctx, Source);
794
+
735
795
TrivialModuleLoader ModLoader;
736
796
auto PP = createPP (Source, ModLoader);
737
797
auto TokLoc = SourceLocation ();
@@ -754,6 +814,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
754
814
RootConstants(b0)
755
815
)cc" ;
756
816
817
+ auto Ctx = createMinimalASTContext ();
818
+ StringLiteral *Signature = wrapSource (Ctx, Source);
819
+
757
820
TrivialModuleLoader ModLoader;
758
821
auto PP = createPP (Source, ModLoader);
759
822
auto TokLoc = SourceLocation ();
@@ -778,6 +841,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
778
841
)
779
842
)cc" ;
780
843
844
+ auto Ctx = createMinimalASTContext ();
845
+ StringLiteral *Signature = wrapSource (Ctx, Source);
846
+
781
847
TrivialModuleLoader ModLoader;
782
848
auto PP = createPP (Source, ModLoader);
783
849
auto TokLoc = SourceLocation ();
@@ -800,6 +866,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
800
866
RootConstants(num32BitConstants = 32, num32BitConstants = 24)
801
867
)cc" ;
802
868
869
+ auto Ctx = createMinimalASTContext ();
870
+ StringLiteral *Signature = wrapSource (Ctx, Source);
871
+
803
872
TrivialModuleLoader ModLoader;
804
873
auto PP = createPP (Source, ModLoader);
805
874
auto TokLoc = SourceLocation ();
@@ -824,6 +893,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
824
893
)
825
894
)cc" ;
826
895
896
+ auto Ctx = createMinimalASTContext ();
897
+ StringLiteral *Signature = wrapSource (Ctx, Source);
898
+
827
899
TrivialModuleLoader ModLoader;
828
900
auto PP = createPP (Source, ModLoader);
829
901
auto TokLoc = SourceLocation ();
@@ -850,6 +922,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
850
922
)
851
923
)cc" ;
852
924
925
+ auto Ctx = createMinimalASTContext ();
926
+ StringLiteral *Signature = wrapSource (Ctx, Source);
927
+
853
928
TrivialModuleLoader ModLoader;
854
929
auto PP = createPP (Source, ModLoader);
855
930
auto TokLoc = SourceLocation ();
@@ -873,6 +948,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
873
948
)
874
949
)cc" ;
875
950
951
+ auto Ctx = createMinimalASTContext ();
952
+ StringLiteral *Signature = wrapSource (Ctx, Source);
953
+
876
954
TrivialModuleLoader ModLoader;
877
955
auto PP = createPP (Source, ModLoader);
878
956
auto TokLoc = SourceLocation ();
@@ -895,6 +973,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
895
973
StaticSampler(s0, mipLODBias = -4294967295)
896
974
)cc" ;
897
975
976
+ auto Ctx = createMinimalASTContext ();
977
+ StringLiteral *Signature = wrapSource (Ctx, Source);
978
+
898
979
TrivialModuleLoader ModLoader;
899
980
auto PP = createPP (Source, ModLoader);
900
981
auto TokLoc = SourceLocation ();
@@ -916,6 +997,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
916
997
StaticSampler(s0, mipLODBias = 3.402823467e+38F)
917
998
)cc" ;
918
999
1000
+ auto Ctx = createMinimalASTContext ();
1001
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1002
+
919
1003
TrivialModuleLoader ModLoader;
920
1004
auto PP = createPP (Source, ModLoader);
921
1005
auto TokLoc = SourceLocation ();
@@ -937,6 +1021,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
937
1021
StaticSampler(s0, mipLODBias = -3.402823467e+38F)
938
1022
)cc" ;
939
1023
1024
+ auto Ctx = createMinimalASTContext ();
1025
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1026
+
940
1027
TrivialModuleLoader ModLoader;
941
1028
auto PP = createPP (Source, ModLoader);
942
1029
auto TokLoc = SourceLocation ();
@@ -958,6 +1045,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
958
1045
StaticSampler(s0, mipLODBias = 1.e+500)
959
1046
)cc" ;
960
1047
1048
+ auto Ctx = createMinimalASTContext ();
1049
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1050
+
961
1051
TrivialModuleLoader ModLoader;
962
1052
auto PP = createPP (Source, ModLoader);
963
1053
auto TokLoc = SourceLocation ();
@@ -979,6 +1069,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
979
1069
StaticSampler(s0, mipLODBias = 10e-309)
980
1070
)cc" ;
981
1071
1072
+ auto Ctx = createMinimalASTContext ();
1073
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1074
+
982
1075
TrivialModuleLoader ModLoader;
983
1076
auto PP = createPP (Source, ModLoader);
984
1077
auto TokLoc = SourceLocation ();
@@ -1003,6 +1096,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
1003
1096
)
1004
1097
)cc" ;
1005
1098
1099
+ auto Ctx = createMinimalASTContext ();
1100
+ StringLiteral *Signature = wrapSource (Ctx, Source);
1101
+
1006
1102
TrivialModuleLoader ModLoader;
1007
1103
auto PP = createPP (Source, ModLoader);
1008
1104
auto TokLoc = SourceLocation ();
0 commit comments