[llvm] r230206 - AsmParser: Check ConstantExpr insertvalue operands for type correctness

David Majnemer david.majnemer at gmail.com
Sun Feb 22 23:13:52 PST 2015


Author: majnemer
Date: Mon Feb 23 01:13:52 2015
New Revision: 230206

URL: http://llvm.org/viewvc/llvm-project?rev=230206&view=rev
Log:
AsmParser: Check ConstantExpr insertvalue operands for type correctness

Added:
    llvm/trunk/test/Assembler/insertvalue-invalid-type-1.ll
Modified:
    llvm/trunk/lib/AsmParser/LLParser.cpp

Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=230206&r1=230205&r2=230206&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Mon Feb 23 01:13:52 2015
@@ -2609,8 +2609,15 @@ bool LLParser::ParseValID(ValID &ID, Per
       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;

Added: llvm/trunk/test/Assembler/insertvalue-invalid-type-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/insertvalue-invalid-type-1.ll?rev=230206&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/insertvalue-invalid-type-1.ll (added)
+++ llvm/trunk/test/Assembler/insertvalue-invalid-type-1.ll Mon Feb 23 01:13:52 2015
@@ -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)
+}





More information about the llvm-commits mailing list