Replacing zero-sized alloca's with a null pointer is too aggressive, instead
authorDuncan Sands <baldrick@free.fr>
Tue, 26 Jun 2012 13:39:21 +0000 (13:39 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 26 Jun 2012 13:39:21 +0000 (13:39 +0000)
commit91fa1da2f73ce77d386cacb1a69f38dcdf7cd60c
tree446595ae1db95df9e03449bf6da17e545706d7c3
parentb787d41959163f6104af7b34a5ce719210dfb72f
Replacing zero-sized alloca's with a null pointer is too aggressive, instead
merge all zero-sized alloca's into one, fixing c43204g from the Ada ACATS
conformance testsuite.  What happened there was that a variable sized object
was being allocated on the stack, "alloca i8, i32 %size".  It was then being
passed to another function, which tested that the address was not null (raising
an exception if it was) then manipulated %size bytes in it (load and/or store).
The optimizers cleverly managed to deduce that %size was zero (congratulations
to them, as it isn't at all obvious), which made the alloca zero size, causing
the optimizers to replace it with null, which then caused the check mentioned
above to fail, and the exception to be raised, wrongly.  Note that no loads
and stores were actually being done to the alloca (the loop that does them is
executed %size times, i.e. is not executed), only the not-null address check.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159202 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
test/Transforms/InstCombine/alloca.ll