diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 86c61bdf66b3..70b681000a71 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3644,6 +3644,9 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) { CurTy = CurTy->subtypes()[0]; } + if (CurTy != Val->getType()) + return Error("Inserted value type doesn't match aggregate type"); + I = InsertValueInst::Create(Agg, Val, INSERTVALIdx); InstructionList.push_back(I); break; diff --git a/llvm/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc b/llvm/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc new file mode 100644 index 000000000000..81333cd6be67 Binary files /dev/null and b/llvm/test/Bitcode/Inputs/invalid-inserted-value-type-mismatch.bc differ diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index 7dd97a4f49a8..921d4e62c049 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -142,3 +142,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-load-ptr-type.bc 2>&1 | \ RUN: FileCheck --check-prefix=BAD-LOAD-PTR-TYPE %s BAD-LOAD-PTR-TYPE: Cannot load/store from pointer + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-inserted-value-type-mismatch.bc 2>&1 | \ +RUN: FileCheck --check-prefix=INSERT-TYPE-MISMATCH %s + +INSERT-TYPE-MISMATCH: Inserted value type doesn't match aggregate type