aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/StackProtector.cpp
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-11-06 02:38:58 +0000
committerBill Wendling <isanbard@gmail.com>2008-11-06 02:38:58 +0000
commit89c5cc6c793ca420194c94361e1c6dacb6d7c446 (patch)
tree870466a97ddaabd30d9a84c26ff98155a210b436 /lib/CodeGen/StackProtector.cpp
parentb2a4298ce41e7ef80cd75a3c1dfa6433f0759a1a (diff)
Adjust the stack protector heuristic to care about only arrays or calls to
"alloca". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@58792 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/StackProtector.cpp')
-rw-r--r--lib/CodeGen/StackProtector.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/CodeGen/StackProtector.cpp b/lib/CodeGen/StackProtector.cpp
index 659f8a01ab..eaf52f691c 100644
--- a/lib/CodeGen/StackProtector.cpp
+++ b/lib/CodeGen/StackProtector.cpp
@@ -184,7 +184,9 @@ BasicBlock *StackProtector::CreateFailBB() {
}
/// 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 @@ bool StackProtector::RequiresStackProtector() const {
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 @@ bool StackProtector::RequiresStackProtector() const {
if (SSPBufferSize <= StackSize)
return true;
+ } else {
+ // This is a call to alloca with a variable size. Default to adding
+ // stack protectors.
+ return true;
}
}
}