llc crash when a const struct includes a zero-length member

When I run llc on the (assembled version of) the following code on Linux x86:

%testType = type {i32, [0 x i32], i32}

define i32 @main() {
  %1 = alloca %testType

  store %testType {i32 1, [0 x i32] zeroinitializer, i32 2}, %testType* %1
  ret i32 0
}

llc crashes with a segmentation fault. It happens in the 2.5 release
version and in the version I pulled from svn trunk about two hours
ago.

The trouble starts in SelectionDAGLowering::getValue(const Value* V),
within the if (isa<ConstantStruct>(C) || isa<ConstantArray>(C)) check,
where the zero-length member (which can be either a zero-length array
or an empty struct) causes getValue(*OI).getNode() to return NULL.
The segfault occurs when this null pointer is used as the instance
pointer for SDNode::getNumValues(). It doesn't matter whether the
zero-length member appears at the beginning, the end, or somewhere in
the middle.

A simple null check on the result of getValue(*OI).getNode() clears up
the segfault and makes my larger test program run properly after
llc'ing and assembling (not surprising, since leaving out the
zero-length member leaves the result of the store unchanged). The
attached patch applied to the svn trunk snapshot should do the trick.

mypatch (844 Bytes)

I just realized that I could get a bugzilla account. I put it in
against the product "new-bugs" and it became Bug 4925.