Skip to content

Commit fbe17f1

Browse files
asudarsaKornevNikita
authored andcommitted
Fix issue due to ignoring return value (#1778)
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com> Original commit: KhronosGroup/SPIRV-LLVM-Translator@e06e46d
1 parent 4be0e5d commit fbe17f1

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,11 @@ bool oclIsBuiltin(StringRef Name, StringRef &DemangledName, bool IsCpp) {
472472
size_t DemangledNameLenStart = NameSpaceStart + 11;
473473
size_t Start = Name.find_first_not_of("0123456789", DemangledNameLenStart);
474474
size_t Len = 0;
475-
Name.substr(DemangledNameLenStart, Start - DemangledNameLenStart)
476-
.getAsInteger(10, Len);
475+
if (Name.substr(DemangledNameLenStart, Start - DemangledNameLenStart)
476+
.getAsInteger(10, Len)) {
477+
SPIRVDBG(errs() << "Error in extracting integer value");
478+
return false;
479+
}
477480
DemangledName = Name.substr(Start, Len);
478481
} else {
479482
size_t Start = Name.find_first_not_of("0123456789", 2);

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,12 @@ SPIRVType *LLVMToSPIRVBase::transSPIRVJointMatrixINTELType(
653653

654654
auto ParseInteger = [this](StringRef Postfix) -> ConstantInt * {
655655
unsigned long long N = 0;
656-
consumeUnsignedInteger(Postfix, 10, N);
656+
if (consumeUnsignedInteger(Postfix, 10, N)) {
657+
BM->getErrorLog().checkError(
658+
false, SPIRVEC_InvalidLlvmModule,
659+
"TypeJointMatrixINTEL expects integer parameters");
660+
return 0;
661+
}
657662
return getUInt32(M, N);
658663
};
659664
std::vector<SPIRVValue *> Args;
@@ -2950,17 +2955,17 @@ void processAnnotationString(IntrinsicInst *II, std::string &AnnotationString) {
29502955
auto *StrValTy = StrVal->getType();
29512956
if (StrValTy->isOpaquePointerTy()) {
29522957
StringRef StrRef;
2953-
getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef);
2954-
AnnotationString += StrRef.str();
2958+
if (getConstantStringInfo(dyn_cast<Constant>(StrVal), StrRef))
2959+
AnnotationString += StrRef.str();
29552960
if (auto *C = dyn_cast_or_null<Constant>(II->getArgOperand(4)))
29562961
processOptionalAnnotationInfo(C, AnnotationString);
29572962
return;
29582963
}
29592964
if (auto *GEP = dyn_cast<GetElementPtrInst>(StrVal)) {
29602965
if (auto *C = dyn_cast<Constant>(GEP->getOperand(0))) {
29612966
StringRef StrRef;
2962-
getConstantStringInfo(C, StrRef);
2963-
AnnotationString += StrRef.str();
2967+
if (getConstantStringInfo(C, StrRef))
2968+
AnnotationString += StrRef.str();
29642969
}
29652970
}
29662971
if (auto *Cast = dyn_cast<BitCastInst>(II->getArgOperand(4)))
@@ -3885,7 +3890,8 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
38853890
return nullptr;
38863891
Constant *C = cast<Constant>(GEP->getOperand(0));
38873892
StringRef AnnotationString;
3888-
getConstantStringInfo(C, AnnotationString);
3893+
if (!getConstantStringInfo(C, AnnotationString))
3894+
return nullptr;
38893895

38903896
if (AnnotationString == kOCLBuiltinName::FPGARegIntel) {
38913897
if (BM->isAllowedToUseExtension(ExtensionID::SPV_INTEL_fpga_reg))
@@ -4379,7 +4385,10 @@ void LLVMToSPIRVBase::transGlobalAnnotation(GlobalVariable *V) {
43794385
cast<GlobalVariable>(CS->getOperand(1)->stripPointerCasts());
43804386

43814387
StringRef AnnotationString;
4382-
getConstantStringInfo(GV, AnnotationString);
4388+
if (!getConstantStringInfo(GV, AnnotationString)) {
4389+
assert(!"Annotation string missing");
4390+
return;
4391+
}
43834392
DecorationsInfoVec Decorations =
43844393
tryParseAnnotationString(BM, AnnotationString).MemoryAttributesVec;
43854394

0 commit comments

Comments
 (0)