[llvm-commits] [llvm] r169216 - /llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Kostya Serebryany kcc at google.com
Mon Dec 3 22:14:01 PST 2012


Author: kcc
Date: Tue Dec  4 00:14:01 2012
New Revision: 169216

URL: http://llvm.org/viewvc/llvm-project?rev=169216&view=rev
Log:
[asan] add experimental -asan-realign-stack option (true by default, which does not change the current behavior) 

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=169216&r1=169215&r2=169216&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Tue Dec  4 00:14:01 2012
@@ -115,6 +115,8 @@
        cl::desc("Handle C++ initializer order"), cl::Hidden, cl::init(false));
 static cl::opt<bool> ClMemIntrin("asan-memintrin",
        cl::desc("Handle memset/memcpy/memmove"), cl::Hidden, cl::init(true));
+static cl::opt<bool> ClRealignStack("asan-realign-stack",
+       cl::desc("Realign stack to 32"), cl::Hidden, cl::init(true));
 static cl::opt<std::string> ClBlacklistFile("asan-blacklist",
        cl::desc("File containing the list of objects to ignore "
                 "during instrumentation"), cl::Hidden);
@@ -1159,6 +1161,7 @@
 
   // Filter out Alloca instructions we want (and can) handle.
   // Collect Ret instructions.
+  unsigned ResultAlignment = 1 << MappingScale();
   for (Function::iterator FI = F.begin(), FE = F.end();
        FI != FE; ++FI) {
     BasicBlock &BB = *FI;
@@ -1174,7 +1177,7 @@
       if (AI->isArrayAllocation()) continue;
       if (!AI->isStaticAlloca()) continue;
       if (!AI->getAllocatedType()->isSized()) continue;
-      if (AI->getAlignment() > RedzoneSize()) continue;
+      ResultAlignment = std::max(ResultAlignment, AI->getAlignment());
       AllocaVec.push_back(AI);
       uint64_t AlignedSize =  getAlignedAllocaSize(AI);
       TotalSize += AlignedSize;
@@ -1195,7 +1198,9 @@
   Type *ByteArrayTy = ArrayType::get(IRB.getInt8Ty(), LocalStackSize);
   AllocaInst *MyAlloca =
       new AllocaInst(ByteArrayTy, "MyAlloca", InsBefore);
-  MyAlloca->setAlignment(RedzoneSize());
+  if (ClRealignStack && ResultAlignment < RedzoneSize())
+    ResultAlignment = RedzoneSize();
+  MyAlloca->setAlignment(ResultAlignment);
   assert(MyAlloca->isStaticAlloca());
   Value *OrigStackBase = IRB.CreatePointerCast(MyAlloca, IntptrTy);
   Value *LocalStackBase = OrigStackBase;





More information about the llvm-commits mailing list