diff options
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Bitcode/Inputs/invalid-cast.bc | bin | 0 -> 1236 bytes | |||
-rw-r--r-- | llvm/test/Bitcode/invalid.test | 5 |
3 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 2893eaef0fb..ce6790be713 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -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; diff --git a/llvm/test/Bitcode/Inputs/invalid-cast.bc b/llvm/test/Bitcode/Inputs/invalid-cast.bc Binary files differnew file mode 100644 index 00000000000..a8b82f3e286 --- /dev/null +++ b/llvm/test/Bitcode/Inputs/invalid-cast.bc diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index 0aab553bb61..69104046df2 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -113,6 +113,11 @@ RUN: FileCheck --check-prefix=ELEMENT-TYPE %s ELEMENT-TYPE: Invalid type +RUN: not llvm-dis -disable-output %p/Inputs/invalid-cast.bc 2>&1 | \ +RUN: FileCheck --check-prefix=INVALID-CAST %s + +INVALID-CAST: Invalid cast + RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-op-not-2nd-to-last.bc 2>&1 | \ RUN: FileCheck --check-prefix=ARRAY-NOT-2LAST %s |