Skip to content

Commit e06e46d

Browse files
authored
Fix issue due to ignoring return value (#1778)
Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 56b3936 commit e06e46d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

lib/SPIRV/SPIRVUtil.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,11 @@ bool oclIsBuiltin(StringRef Name, StringRef &DemangledName, bool IsCpp) {
470470
size_t DemangledNameLenStart = NameSpaceStart + 11;
471471
size_t Start = Name.find_first_not_of("0123456789", DemangledNameLenStart);
472472
size_t Len = 0;
473-
Name.substr(DemangledNameLenStart, Start - DemangledNameLenStart)
474-
.getAsInteger(10, Len);
473+
if (Name.substr(DemangledNameLenStart, Start - DemangledNameLenStart)
474+
.getAsInteger(10, Len)) {
475+
SPIRVDBG(errs() << "Error in extracting integer value");
476+
return false;
477+
}
475478
DemangledName = Name.substr(Start, Len);
476479
} else {
477480
size_t Start = Name.find_first_not_of("0123456789", 2);

lib/SPIRV/SPIRVWriter.cpp

+16-7
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,12 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVJointMatrixINTELType(
649649

650650
auto ParseInteger = [this](StringRef Postfix) -> ConstantInt * {
651651
unsigned long long N = 0;
652-
consumeUnsignedInteger(Postfix, 10, N);
652+
if (consumeUnsignedInteger(Postfix, 10, N)) {
653+
BM->getErrorLog().checkError(
654+
false, SPIRVEC_InvalidLlvmModule,
655+
"TypeJointMatrixINTEL expects integer parameters");
656+
return 0;
657+
}
653658
return getUInt32(M, N);
654659
};
655660
std::vector<SPIRVValue *> Args;
@@ -2886,17 +2891,17 @@ void processAnnotationString(IntrinsicInst *II, std::string &AnnotationString) {
28862891
auto *StrValTy = StrVal->getType();
28872892
if (StrValTy->isOpaquePointerTy()) {
28882893
StringRef StrRef;
2889-
getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef);
2890-
AnnotationString += StrRef.str();
2894+
if (getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef))
2895+
AnnotationString += StrRef.str();
28912896
if (auto *C = dyn_cast_or_null<Constant>(II->getArgOperand(4)))
28922897
processOptionalAnnotationInfo(C, AnnotationString);
28932898
return;
28942899
}
28952900
if (auto *GEP = dyn_cast<GetElementPtrInst>(StrVal)) {
28962901
if (auto *C = dyn_cast<Constant>(GEP->getOperand(0))) {
28972902
StringRef StrRef;
2898-
getConstantStringInfo(C, StrRef);
2899-
AnnotationString += StrRef.str();
2903+
if (getConstantStringInfo(C, StrRef))
2904+
AnnotationString += StrRef.str();
29002905
}
29012906
}
29022907
if (auto *Cast = dyn_cast<BitCastInst>(II->getArgOperand(4)))
@@ -3821,7 +3826,8 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
38213826
return nullptr;
38223827
Constant *C = cast<Constant>(GEP->getOperand(0));
38233828
StringRef AnnotationString;
3824-
getConstantStringInfo(C, AnnotationString);
3829+
if (!getConstantStringInfo(C, AnnotationString))
3830+
return nullptr;
38253831

38263832
if (AnnotationString == kOCLBuiltinName::FPGARegIntel) {
38273833
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fpga_reg))
@@ -4316,7 +4322,10 @@ void LLVMToSPIRVBase::transGlobalAnnotation(GlobalVariable *V) {
43164322
cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
43174323

43184324
StringRef AnnotationString;
4319-
getConstantStringInfo(GV, AnnotationString);
4325+
if (!getConstantStringInfo(GV, AnnotationString)) {
4326+
assert(!"Annotation string missing");
4327+
return;
4328+
}
43204329
DecorationsInfoVec Decorations =
43214330
tryParseAnnotationString(BM, AnnotationString).MemoryAttributesVec;
43224331

0 commit comments

Comments
 (0)