[llvm] r228813 - AsmParser: Don't crash when insertvalue has bad operands

David Majnemer david.majnemer at gmail.com
Tue Feb 10 23:43:58 PST 2015


Author: majnemer
Date: Wed Feb 11 01:43:58 2015
New Revision: 228813

URL: http://llvm.org/viewvc/llvm-project?rev=228813&view=rev
Log:
AsmParser: Don't crash when insertvalue has bad operands

Added:
    llvm/trunk/test/Assembler/insertvalue-invalid-type.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=228813&r1=228812&r2=228813&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Feb 11 01:43:58 2015
@@ -4951,8 +4951,13 @@ int LLParser::ParseInsertValue(Instructi
   if (!Val0->getType()->isAggregateType())
     return Error(Loc0, "insertvalue operand must be aggregate type");
 
-  if (!ExtractValueInst::getIndexedType(Val0->getType(), Indices))
+  Type *IndexedType = ExtractValueInst::getIndexedType(Val0->getType(), Indices);
+  if (!IndexedType)
     return Error(Loc0, "invalid indices for insertvalue");
+  if (IndexedType != Val1->getType())
+    return Error(Loc1, "insertvalue operand and field disagree in type: '" +
+                           getTypeString(Val1->getType()) + "' instead of '" +
+                           getTypeString(IndexedType) + "'");
   Inst = InsertValueInst::Create(Val0, Val1, Indices);
   return AteExtraComma ? InstExtraComma : InstNormal;
 }

Added: llvm/trunk/test/Assembler/insertvalue-invalid-type.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/insertvalue-invalid-type.ll?rev=228813&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/insertvalue-invalid-type.ll (added)
+++ llvm/trunk/test/Assembler/insertvalue-invalid-type.ll Wed Feb 11 01:43:58 2015
@@ -0,0 +1,9 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: insertvalue operand and field disagree in type: 'i8*' instead of 'i32'
+
+define void @test() {
+entry:
+  insertvalue { i32, i32 } undef, i8* null, 0
+  ret void
+}





More information about the llvm-commits mailing list