[LLVMdev] llc crash when a const struct includes a zero-length member

Kenneth Uildriks kennethuil at gmail.com
Sat Sep 5 19:34:59 PDT 2009


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mypatch
Type: application/octet-stream
Size: 844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090905/ed1a0333/attachment.obj>


More information about the llvm-dev mailing list