@@ -2069,36 +2069,42 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI,
2069
2069
2070
2070
#define ONE_STRING_DECORATION_CASE (NAME, NAMESPACE ) \
2071
2071
case NAMESPACE::Decoration##NAME: { \
2072
- assert (NumOperands == 2 && #NAME " requires exactly 1 extra operand" ); \
2072
+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule, \
2073
+ #NAME " requires exactly 1 extra operand" ); \
2073
2074
auto *StrDecoEO = dyn_cast<MDString>(DecoMD->getOperand (1 )); \
2074
- assert (StrDecoEO &&#NAME " requires extra operand to be a string" ); \
2075
+ ErrLog.checkError (StrDecoEO, SPIRVEC_InvalidLlvmModule, \
2076
+ #NAME " requires extra operand to be a string" ); \
2075
2077
Target->addDecorate ( \
2076
2078
new SPIRVDecorate##NAME##Attr (Target, StrDecoEO->getString ().str ())); \
2077
2079
break ; \
2078
2080
}
2079
2081
2080
2082
#define ONE_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE ) \
2081
2083
case NAMESPACE::Decoration##NAME: { \
2082
- assert (NumOperands == 2 && #NAME " requires exactly 1 extra operand" ); \
2084
+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule, \
2085
+ #NAME " requires exactly 1 extra operand" ); \
2083
2086
auto *IntDecoEO = \
2084
2087
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 )); \
2085
- assert (IntDecoEO &&#NAME " requires extra operand to be an integer" ); \
2088
+ ErrLog.checkError (IntDecoEO, SPIRVEC_InvalidLlvmModule, \
2089
+ #NAME " requires extra operand to be an integer" ); \
2086
2090
Target->addDecorate (new SPIRVDecorate##NAME ( \
2087
2091
Target, static_cast <TYPE>(IntDecoEO->getZExtValue ()))); \
2088
2092
break ; \
2089
2093
}
2090
2094
2091
2095
#define TWO_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE1, TYPE2 ) \
2092
2096
case NAMESPACE::Decoration##NAME: { \
2093
- assert (NumOperands == 3 && #NAME " requires exactly 2 extra operand" ); \
2097
+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule, \
2098
+ #NAME " requires exactly 2 extra operands" ); \
2094
2099
auto *IntDecoEO1 = \
2095
2100
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 )); \
2096
- assert (IntDecoEO1 &&#NAME \
2097
- " requires first extra operand to be an integer " ); \
2101
+ ErrLog. checkError (IntDecoEO1, SPIRVEC_InvalidLlvmModule, \
2102
+ #NAME " requires first extra operand to be an integer " ); \
2098
2103
auto *IntDecoEO2 = \
2099
2104
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 )); \
2100
- assert (IntDecoEO2 &&#NAME \
2101
- " requires second extra operand to be an integer" ); \
2105
+ ErrLog.checkError (IntDecoEO2, SPIRVEC_InvalidLlvmModule, \
2106
+ #NAME \
2107
+ " requires second extra operand to be an integer" ); \
2102
2108
Target->addDecorate (new SPIRVDecorate##NAME ( \
2103
2109
Target, static_cast <TYPE1>(IntDecoEO1->getZExtValue ()), \
2104
2110
static_cast <TYPE2>(IntDecoEO2->getZExtValue ()))); \
@@ -2119,16 +2125,20 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
2119
2125
}
2120
2126
2121
2127
static void transMetadataDecorations (Metadata *MD, SPIRVEntry *Target) {
2128
+ SPIRVErrorLog &ErrLog = Target->getErrorLog ();
2129
+
2122
2130
auto *ArgDecoMD = dyn_cast<MDNode>(MD);
2123
2131
assert (ArgDecoMD && " Decoration list must be a metadata node" );
2124
2132
for (unsigned I = 0 , E = ArgDecoMD->getNumOperands (); I != E; ++I) {
2125
2133
auto *DecoMD = dyn_cast<MDNode>(ArgDecoMD->getOperand (I));
2126
- assert (DecoMD && " Decoration does not name metadata" );
2127
- assert (DecoMD->getNumOperands () > 0 &&
2128
- " Decoration metadata must have at least one operand" );
2134
+ ErrLog.checkError (DecoMD, SPIRVEC_InvalidLlvmModule,
2135
+ " Decoration does not name metadata" );
2136
+ ErrLog.checkError (DecoMD->getNumOperands () > 0 , SPIRVEC_InvalidLlvmModule,
2137
+ " Decoration metadata must have at least one operand" );
2129
2138
auto *DecoKindConst =
2130
2139
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (0 ));
2131
- assert (DecoKindConst && " First operand of decoration must be the kind" );
2140
+ ErrLog.checkError (DecoKindConst, SPIRVEC_InvalidLlvmModule,
2141
+ " First operand of decoration must be the kind" );
2132
2142
auto DecoKind = static_cast <Decoration>(DecoKindConst->getZExtValue ());
2133
2143
2134
2144
const size_t NumOperands = DecoMD->getNumOperands ();
@@ -2155,25 +2165,31 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2155
2165
break ;
2156
2166
}
2157
2167
case DecorationMergeINTEL: {
2158
- assert (NumOperands == 3 && " MergeINTEL requires exactly 3 extra operand" );
2168
+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2169
+ " MergeINTEL requires exactly 3 extra operands" );
2159
2170
auto *Name = dyn_cast<MDString>(DecoMD->getOperand (1 ));
2160
- assert (Name && " MergeINTEL requires first extra operand to be a string" );
2171
+ ErrLog.checkError (
2172
+ Name, SPIRVEC_InvalidLlvmModule,
2173
+ " MergeINTEL requires first extra operand to be a string" );
2161
2174
auto *Direction = dyn_cast<MDString>(DecoMD->getOperand (2 ));
2162
- assert (Direction &&
2163
- " MergeINTEL requires second extra operand to be a string" );
2175
+ ErrLog.checkError (
2176
+ Direction, SPIRVEC_InvalidLlvmModule,
2177
+ " MergeINTEL requires second extra operand to be a string" );
2164
2178
Target->addDecorate (new SPIRVDecorateMergeINTELAttr (
2165
2179
Target, Name->getString ().str (), Direction->getString ().str ()));
2166
2180
break ;
2167
2181
}
2168
2182
case DecorationLinkageAttributes: {
2169
- assert (NumOperands == 3 &&
2170
- " LinkageAttributes requires exactly 3 extra operand " );
2183
+ ErrLog. checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2184
+ " LinkageAttributes requires exactly 3 extra operands " );
2171
2185
auto *Name = dyn_cast<MDString>(DecoMD->getOperand (1 ));
2172
- assert (Name &&
2173
- " LinkageAttributes requires first extra operand to be a string" );
2186
+ ErrLog.checkError (
2187
+ Name, SPIRVEC_InvalidLlvmModule,
2188
+ " LinkageAttributes requires first extra operand to be a string" );
2174
2189
auto *Type = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 ));
2175
- assert (Type &&
2176
- " LinkageAttributes requires second extra operand to be an int" );
2190
+ ErrLog.checkError (
2191
+ Type, SPIRVEC_InvalidLlvmModule,
2192
+ " LinkageAttributes requires second extra operand to be an int" );
2177
2193
auto TypeKind = static_cast <SPIRVLinkageTypeKind>(Type->getZExtValue ());
2178
2194
Target->addDecorate (new SPIRVDecorateLinkageAttr (
2179
2195
Target, Name->getString ().str (), TypeKind));
@@ -2182,44 +2198,49 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2182
2198
case spv::internal::DecorationHostAccessINTEL: {
2183
2199
checkIsGlobalVar (Target, DecoKind);
2184
2200
2185
- assert (NumOperands == 3 && " HostAccessINTEL requires 2 extra operands "
2186
- " after the decoration kind number" );
2201
+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2202
+ " HostAccessINTEL requires exactly 2 extra operands "
2203
+ " after the decoration kind number" );
2187
2204
auto *AccessMode =
2188
2205
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2189
- assert (AccessMode &&
2190
- " HostAccessINTEL requires first extra operand to be an int" );
2206
+ ErrLog.checkError (
2207
+ AccessMode, SPIRVEC_InvalidLlvmModule,
2208
+ " HostAccessINTEL requires first extra operand to be an int" );
2191
2209
auto *Name = dyn_cast<MDString>(DecoMD->getOperand (2 ));
2192
- assert (Name &&
2193
- " HostAccessINTEL requires second extra operand to be a string" );
2210
+ ErrLog.checkError (
2211
+ Name, SPIRVEC_InvalidLlvmModule,
2212
+ " HostAccessINTEL requires second extra operand to be a string" );
2194
2213
2195
2214
Target->addDecorate (new SPIRVDecorateHostAccessINTEL (
2196
2215
Target, AccessMode->getZExtValue (), Name->getString ().str ()));
2197
2216
break ;
2198
2217
}
2199
2218
case spv::internal::DecorationInitModeINTEL: {
2200
2219
checkIsGlobalVar (Target, DecoKind);
2201
- assert (static_cast <SPIRVVariable *>(Target)->getInitializer () &&
2202
- " InitModeINTEL only be applied to a global (module scope) "
2203
- " variable which has an Initializer operand" );
2220
+ ErrLog.checkError (static_cast <SPIRVVariable *>(Target)->getInitializer (),
2221
+ SPIRVEC_InvalidLlvmModule,
2222
+ " InitModeINTEL only be applied to a global (module "
2223
+ " scope) variable which has an Initializer operand" );
2204
2224
2205
- assert (NumOperands == 2 &&
2206
- " InitModeINTEL requires exactly 1 extra operand" );
2225
+ ErrLog. checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
2226
+ " InitModeINTEL requires exactly 1 extra operand" );
2207
2227
auto *Trigger = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2208
- assert (Trigger &&
2209
- " InitModeINTEL requires extra operand to be an integer" );
2228
+ ErrLog.checkError (
2229
+ Trigger, SPIRVEC_InvalidLlvmModule,
2230
+ " InitModeINTEL requires extra operand to be an integer" );
2210
2231
2211
2232
Target->addDecorate (
2212
2233
new SPIRVDecorateInitModeINTEL (Target, Trigger->getZExtValue ()));
2213
2234
break ;
2214
2235
}
2215
2236
case spv::internal::DecorationImplementInCSRINTEL: {
2216
2237
checkIsGlobalVar (Target, DecoKind);
2217
-
2218
- assert (NumOperands == 2 &&
2219
- " ImplementInCSRINTEL requires exactly 1 extra operand" );
2238
+ ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
2239
+ " ImplementInCSRINTEL requires exactly 1 extra operand" );
2220
2240
auto *Value = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2221
- assert (Value &&
2222
- " ImplementInCSRINTEL requires extra operand to be an integer" );
2241
+ ErrLog.checkError (
2242
+ Value, SPIRVEC_InvalidLlvmModule,
2243
+ " ImplementInCSRINTEL requires extra operand to be an integer" );
2223
2244
2224
2245
Target->addDecorate (
2225
2246
new SPIRVDecorateImplementInCSRINTEL (Target, Value->getZExtValue ()));
@@ -2233,8 +2254,9 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2233
2254
2234
2255
auto *DecoValEO1 =
2235
2256
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (1 ));
2236
- assert (DecoValEO1 &&
2237
- " First extra operand in default decoration case must be integer." );
2257
+ ErrLog.checkError (
2258
+ DecoValEO1, SPIRVEC_InvalidLlvmModule,
2259
+ " First extra operand in default decoration case must be integer." );
2238
2260
if (NumOperands == 2 ) {
2239
2261
Target->addDecorate (
2240
2262
new SPIRVDecorate (DecoKind, Target, DecoValEO1->getZExtValue ()));
@@ -2243,9 +2265,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2243
2265
2244
2266
auto *DecoValEO2 =
2245
2267
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand (2 ));
2246
- assert (DecoValEO2 &&
2247
- " First extra operand in default decoration case must be integer." );
2248
- assert (NumOperands == 3 && " At most 2 extra operands expected." );
2268
+ ErrLog.checkError (
2269
+ DecoValEO2, SPIRVEC_InvalidLlvmModule,
2270
+ " Second extra operand in default decoration case must be integer." );
2271
+
2272
+ ErrLog.checkError (NumOperands == 3 , SPIRVEC_InvalidLlvmModule,
2273
+ " At most 2 extra operands expected." );
2249
2274
Target->addDecorate (new SPIRVDecorate (DecoKind, Target,
2250
2275
DecoValEO1->getZExtValue (),
2251
2276
DecoValEO2->getZExtValue ()));
0 commit comments