Fix an abort on a store of an empty struct member. getValue returns
authorDan Gohman <gohman@apple.com>
Tue, 8 Sep 2009 01:44:02 +0000 (01:44 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 8 Sep 2009 01:44:02 +0000 (01:44 +0000)
null in the case of an empty struct, so don't try to call getNumValues
on it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81180 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
test/CodeGen/X86/store-empty-member.ll [new file with mode: 0644]

index ce412e01c0e6f813525ce9f06e1ed5e89f33dc07..ad599124fb87e0cc2e736be95649a1f9bdfadd06 100644 (file)
@@ -861,6 +861,10 @@ SDValue SelectionDAGLowering::getValue(const Value *V) {
       for (User::const_op_iterator OI = C->op_begin(), OE = C->op_end();
            OI != OE; ++OI) {
         SDNode *Val = getValue(*OI).getNode();
+        // If the operand is an empty aggregate, there are no values.
+        if (!Val) continue;
+        // Add each leaf value from the operand to the Constants list
+        // to form a flattened list of all the values.
         for (unsigned i = 0, e = Val->getNumValues(); i != e; ++i)
           Constants.push_back(SDValue(Val, i));
       }
diff --git a/test/CodeGen/X86/store-empty-member.ll b/test/CodeGen/X86/store-empty-member.ll
new file mode 100644 (file)
index 0000000..98c1a99
--- /dev/null
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | llc -march=x86 | FileCheck %s
+
+; Don't crash on an empty struct member.
+
+; CHECK: movl  $2, 4(%esp)
+; CHECK: movl  $1, (%esp)
+
+%testType = type {i32, [0 x i32], i32}
+
+define void @foo() nounwind {
+  %1 = alloca %testType
+  volatile store %testType {i32 1, [0 x i32] zeroinitializer, i32 2}, %testType* %1
+  ret void
+}