[llvm-commits] [llvm] r58792 - /llvm/trunk/lib/CodeGen/StackProtector.cpp

Bill Wendling isanbard at gmail.com
Wed Nov 5 18:38:58 PST 2008


Author: void
Date: Wed Nov  5 20:38:58 2008
New Revision: 58792

URL: http://llvm.org/viewvc/llvm-project?rev=58792&view=rev
Log:
Adjust the stack protector heuristic to care about only arrays or calls to
"alloca".

Modified:
    llvm/trunk/lib/CodeGen/StackProtector.cpp

Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=58792&r1=58791&r2=58792&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp Wed Nov  5 20:38:58 2008
@@ -184,7 +184,9 @@
 }
 
 /// RequiresStackProtector - Check whether or not this function needs a stack
-/// protector based upon the stack protector level.
+/// protector based upon the stack protector level. The heuristic we use is to
+/// add a guard variable to functions that call alloca, and functions with
+/// buffers larger than 8 bytes.
 bool StackProtector::RequiresStackProtector() const {
   switch (Level) {
   default: return false;
@@ -201,6 +203,8 @@
       for (BasicBlock::iterator
              II = BB->begin(), IE = BB->end(); II != IE; ++II)
         if (AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
+          if (!AI->isArrayAllocation()) continue; // Only care about arrays.
+
           if (ConstantInt *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
             const Type *Ty = AI->getAllocatedType();
             uint64_t TySize = TD->getABITypeSize(Ty);
@@ -208,6 +212,10 @@
 
             if (SSPBufferSize <= StackSize)
               return true;
+          } else {
+            // This is a call to alloca with a variable size. Default to adding
+            // stack protectors.
+            return true;
           }
         }
     }





More information about the llvm-commits mailing list