diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index e5b8dee10b..671dee81c5 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -2059,9 +2059,11 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI, #define ONE_STRING_DECORATION_CASE(NAME, NAMESPACE) \ case NAMESPACE::Decoration##NAME: { \ - assert(NumOperands == 2 && #NAME " requires exactly 1 extra operand"); \ + ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires exactly 1 extra operand"); \ auto *StrDecoEO = dyn_cast(DecoMD->getOperand(1)); \ - assert(StrDecoEO &&#NAME " requires extra operand to be a string"); \ + ErrLog.checkError(StrDecoEO, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires extra operand to be a string"); \ Target->addDecorate( \ new SPIRVDecorate##NAME##Attr(Target, StrDecoEO->getString().str())); \ break; \ @@ -2069,10 +2071,12 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI, #define ONE_INT_DECORATION_CASE(NAME, NAMESPACE, TYPE) \ case NAMESPACE::Decoration##NAME: { \ - assert(NumOperands == 2 && #NAME " requires exactly 1 extra operand"); \ + ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires exactly 1 extra operand"); \ auto *IntDecoEO = \ mdconst::dyn_extract(DecoMD->getOperand(1)); \ - assert(IntDecoEO &&#NAME " requires extra operand to be an integer"); \ + ErrLog.checkError(IntDecoEO, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires extra operand to be an integer"); \ Target->addDecorate(new SPIRVDecorate##NAME( \ Target, static_cast(IntDecoEO->getZExtValue()))); \ break; \ @@ -2080,15 +2084,17 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI, #define TWO_INT_DECORATION_CASE(NAME, NAMESPACE, TYPE1, TYPE2) \ case NAMESPACE::Decoration##NAME: { \ - assert(NumOperands == 3 && #NAME " requires exactly 2 extra operand"); \ + ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires exactly 2 extra operands"); \ auto *IntDecoEO1 = \ mdconst::dyn_extract(DecoMD->getOperand(1)); \ - assert(IntDecoEO1 &&#NAME \ - " requires first extra operand to be an integer"); \ + ErrLog.checkError(IntDecoEO1, SPIRVEC_InvalidLlvmModule, \ + #NAME " requires first extra operand to be an integer"); \ auto *IntDecoEO2 = \ mdconst::dyn_extract(DecoMD->getOperand(2)); \ - assert(IntDecoEO2 &&#NAME \ - " requires second extra operand to be an integer"); \ + ErrLog.checkError(IntDecoEO2, SPIRVEC_InvalidLlvmModule, \ + #NAME \ + " requires second extra operand to be an integer"); \ Target->addDecorate(new SPIRVDecorate##NAME( \ Target, static_cast(IntDecoEO1->getZExtValue()), \ static_cast(IntDecoEO2->getZExtValue()))); \ @@ -2109,16 +2115,20 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) { } static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { + SPIRVErrorLog &ErrLog = Target->getErrorLog(); + auto *ArgDecoMD = dyn_cast(MD); assert(ArgDecoMD && "Decoration list must be a metadata node"); for (unsigned I = 0, E = ArgDecoMD->getNumOperands(); I != E; ++I) { auto *DecoMD = dyn_cast(ArgDecoMD->getOperand(I)); - assert(DecoMD && "Decoration does not name metadata"); - assert(DecoMD->getNumOperands() > 0 && - "Decoration metadata must have at least one operand"); + ErrLog.checkError(DecoMD, SPIRVEC_InvalidLlvmModule, + "Decoration does not name metadata"); + ErrLog.checkError(DecoMD->getNumOperands() > 0, SPIRVEC_InvalidLlvmModule, + "Decoration metadata must have at least one operand"); auto *DecoKindConst = mdconst::dyn_extract(DecoMD->getOperand(0)); - assert(DecoKindConst && "First operand of decoration must be the kind"); + ErrLog.checkError(DecoKindConst, SPIRVEC_InvalidLlvmModule, + "First operand of decoration must be the kind"); auto DecoKind = static_cast(DecoKindConst->getZExtValue()); const size_t NumOperands = DecoMD->getNumOperands(); @@ -2145,25 +2155,31 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { break; } case DecorationMergeINTEL: { - assert(NumOperands == 3 && "MergeINTEL requires exactly 3 extra operand"); + ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, + "MergeINTEL requires exactly 3 extra operands"); auto *Name = dyn_cast(DecoMD->getOperand(1)); - assert(Name && "MergeINTEL requires first extra operand to be a string"); + ErrLog.checkError( + Name, SPIRVEC_InvalidLlvmModule, + "MergeINTEL requires first extra operand to be a string"); auto *Direction = dyn_cast(DecoMD->getOperand(2)); - assert(Direction && - "MergeINTEL requires second extra operand to be a string"); + ErrLog.checkError( + Direction, SPIRVEC_InvalidLlvmModule, + "MergeINTEL requires second extra operand to be a string"); Target->addDecorate(new SPIRVDecorateMergeINTELAttr( Target, Name->getString().str(), Direction->getString().str())); break; } case DecorationLinkageAttributes: { - assert(NumOperands == 3 && - "LinkageAttributes requires exactly 3 extra operand"); + ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, + "LinkageAttributes requires exactly 3 extra operands"); auto *Name = dyn_cast(DecoMD->getOperand(1)); - assert(Name && - "LinkageAttributes requires first extra operand to be a string"); + ErrLog.checkError( + Name, SPIRVEC_InvalidLlvmModule, + "LinkageAttributes requires first extra operand to be a string"); auto *Type = mdconst::dyn_extract(DecoMD->getOperand(2)); - assert(Type && - "LinkageAttributes requires second extra operand to be an int"); + ErrLog.checkError( + Type, SPIRVEC_InvalidLlvmModule, + "LinkageAttributes requires second extra operand to be an int"); auto TypeKind = static_cast(Type->getZExtValue()); Target->addDecorate(new SPIRVDecorateLinkageAttr( Target, Name->getString().str(), TypeKind)); @@ -2172,15 +2188,18 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { case spv::internal::DecorationHostAccessINTEL: { checkIsGlobalVar(Target, DecoKind); - assert(NumOperands == 3 && "HostAccessINTEL requires 2 extra operands " - "after the decoration kind number"); + ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, + "HostAccessINTEL requires exactly 2 extra operands " + "after the decoration kind number"); auto *AccessMode = mdconst::dyn_extract(DecoMD->getOperand(1)); - assert(AccessMode && - "HostAccessINTEL requires first extra operand to be an int"); + ErrLog.checkError( + AccessMode, SPIRVEC_InvalidLlvmModule, + "HostAccessINTEL requires first extra operand to be an int"); auto *Name = dyn_cast(DecoMD->getOperand(2)); - assert(Name && - "HostAccessINTEL requires second extra operand to be a string"); + ErrLog.checkError( + Name, SPIRVEC_InvalidLlvmModule, + "HostAccessINTEL requires second extra operand to be a string"); Target->addDecorate(new SPIRVDecorateHostAccessINTEL( Target, AccessMode->getZExtValue(), Name->getString().str())); @@ -2188,15 +2207,17 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { } case spv::internal::DecorationInitModeINTEL: { checkIsGlobalVar(Target, DecoKind); - assert(static_cast(Target)->getInitializer() && - "InitModeINTEL only be applied to a global (module scope) " - "variable which has an Initializer operand"); + ErrLog.checkError(static_cast(Target)->getInitializer(), + SPIRVEC_InvalidLlvmModule, + "InitModeINTEL only be applied to a global (module " + "scope) variable which has an Initializer operand"); - assert(NumOperands == 2 && - "InitModeINTEL requires exactly 1 extra operand"); + ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, + "InitModeINTEL requires exactly 1 extra operand"); auto *Trigger = mdconst::dyn_extract(DecoMD->getOperand(1)); - assert(Trigger && - "InitModeINTEL requires extra operand to be an integer"); + ErrLog.checkError( + Trigger, SPIRVEC_InvalidLlvmModule, + "InitModeINTEL requires extra operand to be an integer"); Target->addDecorate( new SPIRVDecorateInitModeINTEL(Target, Trigger->getZExtValue())); @@ -2204,12 +2225,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { } case spv::internal::DecorationImplementInCSRINTEL: { checkIsGlobalVar(Target, DecoKind); - - assert(NumOperands == 2 && - "ImplementInCSRINTEL requires exactly 1 extra operand"); + ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, + "ImplementInCSRINTEL requires exactly 1 extra operand"); auto *Value = mdconst::dyn_extract(DecoMD->getOperand(1)); - assert(Value && - "ImplementInCSRINTEL requires extra operand to be an integer"); + ErrLog.checkError( + Value, SPIRVEC_InvalidLlvmModule, + "ImplementInCSRINTEL requires extra operand to be an integer"); Target->addDecorate( new SPIRVDecorateImplementInCSRINTEL(Target, Value->getZExtValue())); @@ -2223,8 +2244,9 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { auto *DecoValEO1 = mdconst::dyn_extract(DecoMD->getOperand(1)); - assert(DecoValEO1 && - "First extra operand in default decoration case must be integer."); + ErrLog.checkError( + DecoValEO1, SPIRVEC_InvalidLlvmModule, + "First extra operand in default decoration case must be integer."); if (NumOperands == 2) { Target->addDecorate( new SPIRVDecorate(DecoKind, Target, DecoValEO1->getZExtValue())); @@ -2233,9 +2255,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) { auto *DecoValEO2 = mdconst::dyn_extract(DecoMD->getOperand(2)); - assert(DecoValEO2 && - "First extra operand in default decoration case must be integer."); - assert(NumOperands == 3 && "At most 2 extra operands expected."); + ErrLog.checkError( + DecoValEO2, SPIRVEC_InvalidLlvmModule, + "Second extra operand in default decoration case must be integer."); + + ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, + "At most 2 extra operands expected."); Target->addDecorate(new SPIRVDecorate(DecoKind, Target, DecoValEO1->getZExtValue(), DecoValEO2->getZExtValue()));