Based on the failure from http://reviews.llvm.org/D7741. In alloca_instruments_all_paddings.cc we’re using a dynamic alloca, which is being instrumented, but under higher -O levels all the other allocas are being optimized out. So we end up with only a single dynamic alloca to instrument, and zero static allocas. In FunctionStackPoisoner::poisonStack we then have:
assert(AllocaVec.size() > 0 || DynamicAllocaVec.size() > 0); if (ClInstrumentAllocas) // Handle dynamic allocas. for (auto &AllocaCall : DynamicAllocaVec) handleDynamicAllocaCall(AllocaCall); if (AllocaVec.size() == 0) return; …rest of the function
So we skip the “rest of the function” when there are no static allocas (even when we do have dynamic allocas). However, the “rest of the function” is important, as it ensures that the stack is un-poisoned before return. At the very end of the function we have:
if (ClInstrumentAllocas) // Unpoison dynamic allocas. for (auto &AllocaCall : DynamicAllocaVec) unpoisonDynamicAlloca(AllocaCall);
which doesn’t get executed in this case, but it should. This fix just includes this code when we return early from the AllocaVec.size() check in the beginning of the function.
Please add {} for this if as well.