Fix crash with an insertvalue that produces an empty object.
authorPeter Collingbourne <peter@pcc.me.uk>
Sat, 20 Sep 2014 00:10:47 +0000 (00:10 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Sat, 20 Sep 2014 00:10:47 +0000 (00:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218171 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/Generic/empty-insertvalue.ll [new file with mode: 0644]

index 6d302f98f55fd6e183cb8616501348baa41dae94..6a8cd2eb3b168453e171aa47b227500494f2c465 100644 (file)
@@ -3307,6 +3307,12 @@ void SelectionDAGBuilder::visitInsertValue(const InsertValueInst &I) {
   unsigned NumValValues = ValValueVTs.size();
   SmallVector<SDValue, 4> Values(NumAggValues);
 
+  // Ignore an insertvalue that produces an empty object
+  if (!NumAggValues) {
+    setValue(&I, DAG.getUNDEF(MVT(MVT::Other)));
+    return;
+  }
+
   SDValue Agg = getValue(Op0);
   unsigned i = 0;
   // Copy the beginning value(s) from the original aggregate.
diff --git a/test/CodeGen/Generic/empty-insertvalue.ll b/test/CodeGen/Generic/empty-insertvalue.ll
new file mode 100644 (file)
index 0000000..e4cc27c
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llc < %s
+
+define void @f() {
+entry:
+  %0 = insertvalue { [0 x { i8*, i8* }], [0 x { i8*, i64 }] } undef, [0 x { i8*, i8* }] undef, 0
+  ret void
+}