Check for dynamic alloca's when selecting lifetime intrinsics.
authorPete Cooper <peter_cooper@apple.com>
Fri, 17 Oct 2014 22:59:33 +0000 (22:59 +0000)
committerPete Cooper <peter_cooper@apple.com>
Fri, 17 Oct 2014 22:59:33 +0000 (22:59 +0000)
commit185a992dcf94c2fe7966484b705d586d1828d5f7
tree6526ccf6cee7115f82ddab6bbab2d68b7fc8a286
parent3b362b35682d41a0c7868264c34dba74b0cb7437
Check for dynamic alloca's when selecting lifetime intrinsics.

TL;DR: Indexing maps with [] creates missing entries.

The long version:

When selecting lifetime intrinsics, we index the *static* alloca map with the AllocaInst we find for that lifetime.  Trouble is, we don't first check to see if this is a dynamic alloca.

On the attached example, this causes a dynamic alloca to create an entry in the static map, and returns 0 (the default) as the frame index for that lifetime.  0 was used for the frame index of the stack protector, which given that it now has a lifetime, is coloured, and merged with other stack slots.

PEI would later trigger an assert because it expects the stack protector to not be dead.

This fix ensures that we only get frame indices for static allocas, ie, those in the map.  Dynamic ones are effectively dropped, which is suboptimal, but at least isn't completely broken.

rdar://problem/18672951

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220099 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
test/CodeGen/X86/dynamic-alloca-lifetime.ll [new file with mode: 0644]