[PATCH] [compiler-rt] Fix alloca_instruments_all_paddings.cc test to work under higher -O levels

Kuba Brecka kuba.brecka at gmail.com
Sat Feb 21 02:35:32 PST 2015


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.

http://reviews.llvm.org/D7810

Files:
  lib/Transforms/Instrumentation/AddressSanitizer.cpp
  projects/compiler-rt/test/asan/TestCases/alloca_instruments_all_paddings.cc

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7810.20462.patch
Type: text/x-patch
Size: 16942 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150221/51143629/attachment.bin>


More information about the llvm-commits mailing list