From 749c0292c1ecb1f5dc5b506d7e98564b48dae91a Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 23 Feb 2015 07:13:52 +0000 Subject: [PATCH] AsmParser: Check ConstantExpr insertvalue operands for type correctness git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230206 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AsmParser/LLParser.cpp | 9 ++++++++- test/Assembler/insertvalue-invalid-type-1.ll | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/Assembler/insertvalue-invalid-type-1.ll diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index f8eb1305ccd..9e7354e02f7 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -2609,8 +2609,15 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) { return true; if (!Val0->getType()->isAggregateType()) return Error(ID.Loc, "insertvalue operand must be aggregate type"); - if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices)) + Type *IndexedType = + ExtractValueInst::getIndexedType(Val0->getType(), Indices); + if (!IndexedType) return Error(ID.Loc, "invalid indices for insertvalue"); + if (IndexedType != Val1->getType()) + return Error(ID.Loc, "insertvalue operand and field disagree in type: '" + + getTypeString(Val1->getType()) + + "' instead of '" + getTypeString(IndexedType) + + "'"); ID.ConstantVal = ConstantExpr::getInsertValue(Val0, Val1, Indices); ID.Kind = ValID::t_Constant; return false; diff --git a/test/Assembler/insertvalue-invalid-type-1.ll b/test/Assembler/insertvalue-invalid-type-1.ll new file mode 100644 index 00000000000..de9b782874b --- /dev/null +++ b/test/Assembler/insertvalue-invalid-type-1.ll @@ -0,0 +1,7 @@ +; RUN: not llvm-as < %s 2>&1 | FileCheck %s + +; CHECK: insertvalue operand and field disagree in type: 'i32' instead of 'i64' + +define <{ i32 }> @test() { + ret <{ i32 }> insertvalue (<{ i64 }> zeroinitializer, i32 4, 0) +} -- 2.34.1