Make sure the CastInst is valid before trying to create it
[oota-llvm.git] / lib / Bitcode / Reader / BitcodeReader.cpp
index 2893eaef0fb14982c0de7b172460969d67e20c42..ce6790be71373b23133d5d6d135a14cc2747dbc5 100644 (file)
@@ -3863,7 +3863,10 @@ std::error_code BitcodeReader::parseFunctionBody(Function *F) {
           CurBB->getInstList().push_back(Temp);
         }
       } else {
-        I = CastInst::Create((Instruction::CastOps)Opc, Op, ResTy);
+        auto CastOp = (Instruction::CastOps)Opc;
+        if (!CastInst::castIsValid(CastOp, Op, ResTy))
+          return error("Invalid cast");
+        I = CastInst::Create(CastOp, Op, ResTy);
       }
       InstructionList.push_back(I);
       break;