@@ -29,25 +29,18 @@ static bool reportError(Twine Message) {
2929 return true ;
3030}
3131
32- static bool parseRootFlags (ModuleRootSignature *MRS, MDNode *RootFlagNode) {
32+ bool ModuleRootSignature:: parseRootFlags (MDNode *RootFlagNode) {
3333
3434 if (RootFlagNode->getNumOperands () != 2 )
3535 return reportError (" Invalid format for RootFlag Element" );
3636
3737 auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand (1 ));
38- uint32_t Value = Flag->getZExtValue ();
38+ this -> Flags = Flag->getZExtValue ();
3939
40- // Root Element validation, as specified:
41- // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
42- if ((Value & ~0x80000fff ) != 0 )
43- return reportError (" Invalid flag value for RootFlag" );
44-
45- MRS->Flags = Value;
4640 return false ;
4741}
4842
49- static bool parseRootSignatureElement (ModuleRootSignature *MRS,
50- MDNode *Element) {
43+ bool ModuleRootSignature::parseRootSignatureElement (MDNode *Element) {
5144 MDString *ElementText = cast<MDString>(Element->getOperand (0 ));
5245 if (ElementText == nullptr )
5346 return reportError (" Invalid format for Root Element" );
@@ -67,7 +60,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
6760 switch (ElementKind) {
6861
6962 case RootSignatureElementKind::RootFlags: {
70- return parseRootFlags (MRS, Element);
63+ return parseRootFlags (Element);
7164 break ;
7265 }
7366
@@ -131,19 +124,35 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
131124 if (Element == nullptr )
132125 return reportError (" Missing Root Element Metadata Node." );
133126
134- HasError = HasError || parseRootSignatureElement (this , Element);
127+ HasError = HasError || parseRootSignatureElement (Element);
135128 }
136129 }
137130 return HasError;
138131}
139132
133+ bool ModuleRootSignature::validateRootFlag () {
134+ // Root Element validation, as specified:
135+ // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
136+ if ((Flags & ~0x80000fff ) != 0 )
137+ return reportError (" Invalid flag value for RootFlag" );
138+
139+ return false ;
140+ }
141+
142+ bool ModuleRootSignature::validate () {
143+ if (validateRootFlag ())
144+ return reportError (" Invalid flag value for RootFlag" );
145+
146+ return false ;
147+ }
148+
140149ModuleRootSignature ModuleRootSignature::analyzeModule (Module &M,
141150 const Function *F) {
142151 ModuleRootSignature MRS;
143152
144153 NamedMDNode *RootSignatureNode = M.getNamedMetadata (" dx.rootsignatures" );
145154 if (RootSignatureNode) {
146- if (MRS.parse (RootSignatureNode, F))
155+ if (MRS.parse (RootSignatureNode, F) || MRS. validate () )
147156 llvm_unreachable (" Invalid Root Signature Metadata." );
148157 }
149158
@@ -176,7 +185,7 @@ bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
176185 assert (MMI.EntryPropertyVec .size () == 1 );
177186
178187 const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
179- this -> MRS = MRS = ModuleRootSignature::analyzeModule (M, EntryFunction);
188+ MRS = ModuleRootSignature::analyzeModule (M, EntryFunction);
180189
181190 return false ;
182191}
0 commit comments