AsmParser: Check ConstantExpr insertvalue operands for type correctness
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 23 Feb 2015 07:13:52 +0000 (07:13 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 23 Feb 2015 07:13:52 +0000 (07:13 +0000)
llvm-svn: 230206

llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/insertvalue-invalid-type-1.ll [new file with mode: 0644]

index f8eb130..9e7354e 100644 (file)
@@ -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/llvm/test/Assembler/insertvalue-invalid-type-1.ll b/llvm/test/Assembler/insertvalue-invalid-type-1.ll
new file mode 100644 (file)
index 0000000..de9b782
--- /dev/null
@@ -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)
+}