Skip to content

Commit b68afd7

Browse files
committed
[Bitcode] Check validity of fcmp/icmp predicate
The predicate should match the operand types.
1 parent d1deeae commit b68afd7

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5248,7 +5248,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
52485248
return error(
52495249
"Invalid record: operand number exceeded available operands");
52505250

5251-
unsigned PredVal = Record[OpNum];
5251+
CmpInst::Predicate PredVal = CmpInst::Predicate(Record[OpNum]);
52525252
bool IsFP = LHS->getType()->isFPOrFPVectorTy();
52535253
FastMathFlags FMF;
52545254
if (IsFP && Record.size() > OpNum+1)
@@ -5257,10 +5257,15 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
52575257
if (OpNum+1 != Record.size())
52585258
return error("Invalid record");
52595259

5260-
if (LHS->getType()->isFPOrFPVectorTy())
5261-
I = new FCmpInst((FCmpInst::Predicate)PredVal, LHS, RHS);
5262-
else
5263-
I = new ICmpInst((ICmpInst::Predicate)PredVal, LHS, RHS);
5260+
if (IsFP) {
5261+
if (!CmpInst::isFPPredicate(PredVal))
5262+
return error("Invalid fcmp predicate");
5263+
I = new FCmpInst(PredVal, LHS, RHS);
5264+
} else {
5265+
if (!CmpInst::isIntPredicate(PredVal))
5266+
return error("Invalid icmp predicate");
5267+
I = new ICmpInst(PredVal, LHS, RHS);
5268+
}
52645269

52655270
ResTypeID = getVirtualTypeID(I->getType()->getScalarType());
52665271
if (LHS->getType()->isVectorTy())

0 commit comments

Comments
 (0)