@@ -2059,36 +2059,42 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI,
2059
2059
2060
2060
#define ONE_STRING_DECORATION_CASE (NAME, NAMESPACE ) \
2061
2061
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" ); \
2063
2064
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" ); \
2065
2067
Target->addDecorate ( \
2066
2068
new SPIRVDecorate##NAME##Attr (Target, StrDecoEO->getString ().str ())); \
2067
2069
break ; \
2068
2070
}
2069
2071
2070
2072
#define ONE_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE ) \
2071
2073
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" ); \
2073
2076
auto *IntDecoEO = \
2074
2077
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" ); \
2076
2080
Target->addDecorate (new SPIRVDecorate##NAME ( \
2077
2081
Target, static_cast <TYPE>(IntDecoEO->getZExtValue ()))); \
2078
2082
break ; \
2079
2083
}
2080
2084
2081
2085
#define TWO_INT_DECORATION_CASE (NAME, NAMESPACE, TYPE1, TYPE2 ) \
2082
2086
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" ); \
2084
2089
auto *IntDecoEO1 = \
2085
2090
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 " ); \
2088
2093
auto *IntDecoEO2 = \
2089
2094
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" ); \
2092
2098
Target->addDecorate (new SPIRVDecorate##NAME ( \
2093
2099
Target, static_cast <TYPE1>(IntDecoEO1->getZExtValue ()), \
2094
2100
static_cast <TYPE2>(IntDecoEO2->getZExtValue ()))); \
@@ -2109,16 +2115,20 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
2109
2115
}
2110
2116
2111
2117
static void transMetadataDecorations (Metadata *MD, SPIRVEntry *Target) {
2118
+ SPIRVErrorLog &ErrLog = Target->getErrorLog ();
2119
+
2112
2120
auto *ArgDecoMD = dyn_cast<MDNode>(MD);
2113
2121
assert (ArgDecoMD && " Decoration list must be a metadata node" );
2114
2122
for (unsigned I = 0 , E = ArgDecoMD->getNumOperands (); I != E; ++I) {
2115
2123
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" );
2119
2128
auto *DecoKindConst =
2120
2129
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" );
2122
2132
auto DecoKind = static_cast <Decoration>(DecoKindConst->getZExtValue ());
2123
2133
2124
2134
const size_t NumOperands = DecoMD->getNumOperands ();
@@ -2145,25 +2155,31 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2145
2155
break ;
2146
2156
}
2147
2157
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" );
2149
2160
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" );
2151
2164
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" );
2154
2168
Target->addDecorate (new SPIRVDecorateMergeINTELAttr (
2155
2169
Target, Name->getString ().str (), Direction->getString ().str ()));
2156
2170
break ;
2157
2171
}
2158
2172
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 " );
2161
2175
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" );
2164
2179
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" );
2167
2183
auto TypeKind = static_cast <SPIRVLinkageTypeKind>(Type->getZExtValue ());
2168
2184
Target->addDecorate (new SPIRVDecorateLinkageAttr (
2169
2185
Target, Name->getString ().str (), TypeKind));
@@ -2172,44 +2188,49 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2172
2188
case spv::internal::DecorationHostAccessINTEL: {
2173
2189
checkIsGlobalVar (Target, DecoKind);
2174
2190
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" );
2177
2194
auto *AccessMode =
2178
2195
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" );
2181
2199
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" );
2184
2203
2185
2204
Target->addDecorate (new SPIRVDecorateHostAccessINTEL (
2186
2205
Target, AccessMode->getZExtValue (), Name->getString ().str ()));
2187
2206
break ;
2188
2207
}
2189
2208
case spv::internal::DecorationInitModeINTEL: {
2190
2209
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" );
2194
2214
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" );
2197
2217
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" );
2200
2221
2201
2222
Target->addDecorate (
2202
2223
new SPIRVDecorateInitModeINTEL (Target, Trigger->getZExtValue ()));
2203
2224
break ;
2204
2225
}
2205
2226
case spv::internal::DecorationImplementInCSRINTEL: {
2206
2227
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" );
2210
2230
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" );
2213
2234
2214
2235
Target->addDecorate (
2215
2236
new SPIRVDecorateImplementInCSRINTEL (Target, Value->getZExtValue ()));
@@ -2223,8 +2244,9 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2223
2244
2224
2245
auto *DecoValEO1 =
2225
2246
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." );
2228
2250
if (NumOperands == 2 ) {
2229
2251
Target->addDecorate (
2230
2252
new SPIRVDecorate (DecoKind, Target, DecoValEO1->getZExtValue ()));
@@ -2233,9 +2255,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
2233
2255
2234
2256
auto *DecoValEO2 =
2235
2257
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." );
2239
2264
Target->addDecorate (new SPIRVDecorate (DecoKind, Target,
2240
2265
DecoValEO1->getZExtValue (),
2241
2266
DecoValEO2->getZExtValue ()));
0 commit comments