diff options
author | Nikita Popov <npopov@redhat.com> | 2023-12-11 12:51:46 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-12-11 12:54:59 +0100 |
commit | b68afd7b51769796cf920d7926bad3067c7092a1 (patch) | |
tree | b782b154971c4f613b3b0e6cae4ba1178b09646a /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | d1deeae0946aad2de36153f3462575813ace88fd (diff) | |
download | llvm-b68afd7b51769796cf920d7926bad3067c7092a1.zip llvm-b68afd7b51769796cf920d7926bad3067c7092a1.tar.gz llvm-b68afd7b51769796cf920d7926bad3067c7092a1.tar.bz2 |
[Bitcode] Check validity of fcmp/icmp predicate
The predicate should match the operand types.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index e345167..a11690a 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()) |