[llvm] b68afd7 - [Bitcode] Check validity of fcmp/icmp predicate
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 03:55:07 PST 2023
Author: Nikita Popov
Date: 2023-12-11T12:54:59+01:00
New Revision: b68afd7b51769796cf920d7926bad3067c7092a1
URL: https://github.com/llvm/llvm-project/commit/b68afd7b51769796cf920d7926bad3067c7092a1
DIFF: https://github.com/llvm/llvm-project/commit/b68afd7b51769796cf920d7926bad3067c7092a1.diff
LOG: [Bitcode] Check validity of fcmp/icmp predicate
The predicate should match the operand types.
Added:
Modified:
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index e3451675c213f..a11690a19a0e6 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5248,7 +5248,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
return error(
"Invalid record: operand number exceeded available operands");
- unsigned PredVal = Record[OpNum];
+ CmpInst::Predicate PredVal = CmpInst::Predicate(Record[OpNum]);
bool IsFP = LHS->getType()->isFPOrFPVectorTy();
FastMathFlags FMF;
if (IsFP && Record.size() > OpNum+1)
@@ -5257,10 +5257,15 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
if (OpNum+1 != Record.size())
return error("Invalid record");
- if (LHS->getType()->isFPOrFPVectorTy())
- I = new FCmpInst((FCmpInst::Predicate)PredVal, LHS, RHS);
- else
- I = new ICmpInst((ICmpInst::Predicate)PredVal, LHS, RHS);
+ if (IsFP) {
+ if (!CmpInst::isFPPredicate(PredVal))
+ return error("Invalid fcmp predicate");
+ I = new FCmpInst(PredVal, LHS, RHS);
+ } else {
+ if (!CmpInst::isIntPredicate(PredVal))
+ return error("Invalid icmp predicate");
+ I = new ICmpInst(PredVal, LHS, RHS);
+ }
ResTypeID = getVirtualTypeID(I->getType()->getScalarType());
if (LHS->getType()->isVectorTy())
More information about the llvm-commits
mailing list