From b68afd7b51769796cf920d7926bad3067c7092a1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 11 Dec 2023 12:51:46 +0100 Subject: [Bitcode] Check validity of fcmp/icmp predicate The predicate should match the operand types. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') 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()) -- cgit v1.1