@@ -2059,36 +2059,42 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI,
20592059
20602060#define ONE_STRING_DECORATION_CASE (NAME, NAMESPACE ) \
20612061 case NAMESPACE::Decoration##NAME: { \
2062- assert (NumOperands == 2 && #NAME " requires exactly 1 extra operand" ); \
2062+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule, \
2063+ #NAME " requires exactly 1 extra operand" ); \
20632064 auto *StrDecoEO = dyn_cast<MDString>(DecoMD->getOperand (1 )); \
2064- assert (StrDecoEO &&#NAME " requires extra operand to be a string" ); \
2065+ ErrLog.checkError (StrDecoEO, SPIRVEC_InvalidLlvmModule, \
2066+ #NAME " requires extra operand to be a string" ); \
20652067 Target->addDecorate ( \
20662068 new SPIRVDecorate##NAME##Attr (Target, StrDecoEO->getString ().str ())); \
20672069 break ; \
20682070 }
20692071
20702072#define ONE_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE ) \
20712073 case NAMESPACE::Decoration##NAME: { \
2072- assert (NumOperands == 2 && #NAME " requires exactly 1 extra operand" ); \
2074+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule, \
2075+ #NAME " requires exactly 1 extra operand" ); \
20732076 auto *IntDecoEO = \
20742077 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 )); \
2075- assert (IntDecoEO &&#NAME " requires extra operand to be an integer" ); \
2078+ ErrLog.checkError (IntDecoEO, SPIRVEC_InvalidLlvmModule, \
2079+ #NAME " requires extra operand to be an integer" ); \
20762080 Target->addDecorate (new SPIRVDecorate##NAME ( \
20772081 Target, static_cast <TYPE>(IntDecoEO->getZExtValue ()))); \
20782082 break ; \
20792083 }
20802084
20812085#define TWO_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE1, TYPE2 ) \
20822086 case NAMESPACE::Decoration##NAME: { \
2083- assert (NumOperands == 3 && #NAME " requires exactly 2 extra operand" ); \
2087+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule, \
2088+ #NAME " requires exactly 2 extra operands" ); \
20842089 auto *IntDecoEO1 = \
20852090 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 )); \
2086- assert (IntDecoEO1 &&#NAME \
2087- " requires first extra operand to be an integer " ); \
2091+ ErrLog. checkError (IntDecoEO1, SPIRVEC_InvalidLlvmModule, \
2092+ #NAME " requires first extra operand to be an integer " ); \
20882093 auto *IntDecoEO2 = \
20892094 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 )); \
2090- assert (IntDecoEO2 &&#NAME \
2091- " requires second extra operand to be an integer" ); \
2095+ ErrLog.checkError (IntDecoEO2, SPIRVEC_InvalidLlvmModule, \
2096+ #NAME \
2097+ " requires second extra operand to be an integer" ); \
20922098 Target->addDecorate (new SPIRVDecorate##NAME ( \
20932099 Target, static_cast <TYPE1>(IntDecoEO1->getZExtValue ()), \
20942100 static_cast <TYPE2>(IntDecoEO2->getZExtValue ()))); \
@@ -2109,16 +2115,20 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
21092115}
21102116
21112117static void transMetadataDecorations (Metadata *MD, SPIRVEntry *Target) {
2118+ SPIRVErrorLog &ErrLog = Target->getErrorLog ();
2119+
21122120 auto *ArgDecoMD = dyn_cast<MDNode>(MD);
21132121 assert (ArgDecoMD && " Decoration list must be a metadata node" );
21142122 for (unsigned I = 0 , E = ArgDecoMD->getNumOperands (); I != E; ++I) {
21152123 auto *DecoMD = dyn_cast<MDNode>(ArgDecoMD->getOperand (I));
2116- assert (DecoMD && " Decoration does not name metadata" );
2117- assert (DecoMD->getNumOperands () > 0 &&
2118- " Decoration metadata must have at least one operand" );
2124+ ErrLog.checkError (DecoMD, SPIRVEC_InvalidLlvmModule,
2125+ " Decoration does not name metadata" );
2126+ ErrLog.checkError (DecoMD->getNumOperands () > 0 , SPIRVEC_InvalidLlvmModule,
2127+ " Decoration metadata must have at least one operand" );
21192128 auto *DecoKindConst =
21202129 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (0 ));
2121- assert (DecoKindConst && " First operand of decoration must be the kind" );
2130+ ErrLog.checkError (DecoKindConst, SPIRVEC_InvalidLlvmModule,
2131+ " First operand of decoration must be the kind" );
21222132 auto DecoKind = static_cast <Decoration>(DecoKindConst->getZExtValue ());
21232133
21242134 const size_t NumOperands = DecoMD->getNumOperands ();
@@ -2145,25 +2155,31 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
21452155 break ;
21462156 }
21472157 case DecorationMergeINTEL: {
2148- assert (NumOperands == 3 && " MergeINTEL requires exactly 3 extra operand" );
2158+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2159+ " MergeINTEL requires exactly 3 extra operands" );
21492160 auto *Name = dyn_cast<MDString>(DecoMD->getOperand (1 ));
2150- assert (Name && " MergeINTEL requires first extra operand to be a string" );
2161+ ErrLog.checkError (
2162+ Name, SPIRVEC_InvalidLlvmModule,
2163+ " MergeINTEL requires first extra operand to be a string" );
21512164 auto *Direction = dyn_cast<MDString>(DecoMD->getOperand (2 ));
2152- assert (Direction &&
2153- " MergeINTEL requires second extra operand to be a string" );
2165+ ErrLog.checkError (
2166+ Direction, SPIRVEC_InvalidLlvmModule,
2167+ " MergeINTEL requires second extra operand to be a string" );
21542168 Target->addDecorate (new SPIRVDecorateMergeINTELAttr (
21552169 Target, Name->getString ().str (), Direction->getString ().str ()));
21562170 break ;
21572171 }
21582172 case DecorationLinkageAttributes: {
2159- assert (NumOperands == 3 &&
2160- " LinkageAttributes requires exactly 3 extra operand " );
2173+ ErrLog. checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2174+ " LinkageAttributes requires exactly 3 extra operands " );
21612175 auto *Name = dyn_cast<MDString>(DecoMD->getOperand (1 ));
2162- assert (Name &&
2163- " LinkageAttributes requires first extra operand to be a string" );
2176+ ErrLog.checkError (
2177+ Name, SPIRVEC_InvalidLlvmModule,
2178+ " LinkageAttributes requires first extra operand to be a string" );
21642179 auto *Type = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 ));
2165- assert (Type &&
2166- " LinkageAttributes requires second extra operand to be an int" );
2180+ ErrLog.checkError (
2181+ Type, SPIRVEC_InvalidLlvmModule,
2182+ " LinkageAttributes requires second extra operand to be an int" );
21672183 auto TypeKind = static_cast <SPIRVLinkageTypeKind>(Type->getZExtValue ());
21682184 Target->addDecorate (new SPIRVDecorateLinkageAttr (
21692185 Target, Name->getString ().str (), TypeKind));
@@ -2172,44 +2188,49 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
21722188 case spv::internal::DecorationHostAccessINTEL: {
21732189 checkIsGlobalVar (Target, DecoKind);
21742190
2175- assert (NumOperands == 3 && " HostAccessINTEL requires 2 extra operands "
2176- " after the decoration kind number" );
2191+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2192+ " HostAccessINTEL requires exactly 2 extra operands "
2193+ " after the decoration kind number" );
21772194 auto *AccessMode =
21782195 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2179- assert (AccessMode &&
2180- " HostAccessINTEL requires first extra operand to be an int" );
2196+ ErrLog.checkError (
2197+ AccessMode, SPIRVEC_InvalidLlvmModule,
2198+ " HostAccessINTEL requires first extra operand to be an int" );
21812199 auto *Name = dyn_cast<MDString>(DecoMD->getOperand (2 ));
2182- assert (Name &&
2183- " HostAccessINTEL requires second extra operand to be a string" );
2200+ ErrLog.checkError (
2201+ Name, SPIRVEC_InvalidLlvmModule,
2202+ " HostAccessINTEL requires second extra operand to be a string" );
21842203
21852204 Target->addDecorate (new SPIRVDecorateHostAccessINTEL (
21862205 Target, AccessMode->getZExtValue (), Name->getString ().str ()));
21872206 break ;
21882207 }
21892208 case spv::internal::DecorationInitModeINTEL: {
21902209 checkIsGlobalVar (Target, DecoKind);
2191- assert (static_cast <SPIRVVariable *>(Target)->getInitializer () &&
2192- " InitModeINTEL only be applied to a global (module scope) "
2193- " variable which has an Initializer operand" );
2210+ ErrLog.checkError (static_cast <SPIRVVariable *>(Target)->getInitializer (),
2211+ SPIRVEC_InvalidLlvmModule,
2212+ " InitModeINTEL only be applied to a global (module "
2213+ " scope) variable which has an Initializer operand" );
21942214
2195- assert (NumOperands == 2 &&
2196- " InitModeINTEL requires exactly 1 extra operand" );
2215+ ErrLog. checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
2216+ " InitModeINTEL requires exactly 1 extra operand" );
21972217 auto *Trigger = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2198- assert (Trigger &&
2199- " InitModeINTEL requires extra operand to be an integer" );
2218+ ErrLog.checkError (
2219+ Trigger, SPIRVEC_InvalidLlvmModule,
2220+ " InitModeINTEL requires extra operand to be an integer" );
22002221
22012222 Target->addDecorate (
22022223 new SPIRVDecorateInitModeINTEL (Target, Trigger->getZExtValue ()));
22032224 break ;
22042225 }
22052226 case spv::internal::DecorationImplementInCSRINTEL: {
22062227 checkIsGlobalVar (Target, DecoKind);
2207-
2208- assert (NumOperands == 2 &&
2209- " ImplementInCSRINTEL requires exactly 1 extra operand" );
2228+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
2229+ " ImplementInCSRINTEL requires exactly 1 extra operand" );
22102230 auto *Value = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2211- assert (Value &&
2212- " ImplementInCSRINTEL requires extra operand to be an integer" );
2231+ ErrLog.checkError (
2232+ Value, SPIRVEC_InvalidLlvmModule,
2233+ " ImplementInCSRINTEL requires extra operand to be an integer" );
22132234
22142235 Target->addDecorate (
22152236 new SPIRVDecorateImplementInCSRINTEL (Target, Value->getZExtValue ()));
@@ -2223,8 +2244,9 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
22232244
22242245 auto *DecoValEO1 =
22252246 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2226- assert (DecoValEO1 &&
2227- " First extra operand in default decoration case must be integer." );
2247+ ErrLog.checkError (
2248+ DecoValEO1, SPIRVEC_InvalidLlvmModule,
2249+ " First extra operand in default decoration case must be integer." );
22282250 if (NumOperands == 2 ) {
22292251 Target->addDecorate (
22302252 new SPIRVDecorate (DecoKind, Target, DecoValEO1->getZExtValue ()));
@@ -2233,9 +2255,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
22332255
22342256 auto *DecoValEO2 =
22352257 mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 ));
2236- assert (DecoValEO2 &&
2237- " First extra operand in default decoration case must be integer." );
2238- assert (NumOperands == 3 && " At most 2 extra operands expected." );
2258+ ErrLog.checkError (
2259+ DecoValEO2, SPIRVEC_InvalidLlvmModule,
2260+ " Second extra operand in default decoration case must be integer." );
2261+
2262+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2263+ " At most 2 extra operands expected." );
22392264 Target->addDecorate (new SPIRVDecorate (DecoKind, Target,
22402265 DecoValEO1->getZExtValue (),
22412266 DecoValEO2->getZExtValue ()));
0 commit comments