Reformat code with clang-format.

Differential Revision: http://llvm-reviews.chandlerc.com/D2057


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193672 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Josh Magee 2013-10-30 02:25:14 +00:00
parent 9794186889
commit 62406fdc6f
2 changed files with 46 additions and 42 deletions

View File

@ -45,7 +45,7 @@ public:
};
/// A mapping of AllocaInsts to their required SSP layout.
typedef ValueMap<const AllocaInst*, SSPLayoutKind> SSPLayoutMap;
typedef ValueMap<const AllocaInst *, SSPLayoutKind> SSPLayoutMap;
private:
const TargetMachine *TM;
@ -73,7 +73,7 @@ private:
/// if a variable's reference has been taken. This set
/// is maintained to ensure we don't visit the same PHI node multiple
/// times.
SmallPtrSet<const PHINode*, 16> VisitedPHIs;
SmallPtrSet<const PHINode *, 16> VisitedPHIs;
/// InsertStackProtectors - Insert code into the prologue and epilogue of
/// the function.
@ -102,6 +102,7 @@ private:
/// RequiresStackProtector - Check whether or not this function needs a
/// stack protector based upon the stack protector level.
bool RequiresStackProtector();
public:
static char ID; // Pass identification, replacement for typeid.
StackProtector() : FunctionPass(ID), TM(0), TLI(0), SSPBufferSize(0) {

View File

@ -42,20 +42,19 @@ STATISTIC(NumFunProtected, "Number of functions protected");
STATISTIC(NumAddrTaken, "Number of local variables that have their address"
" taken.");
static cl::opt<bool>
EnableSelectionDAGSP("enable-selectiondag-sp", cl::init(true),
cl::Hidden);
static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
cl::init(true), cl::Hidden);
char StackProtector::ID = 0;
INITIALIZE_PASS(StackProtector, "stack-protector",
"Insert stack protectors", false, true)
INITIALIZE_PASS(StackProtector, "stack-protector", "Insert stack protectors",
false, true)
FunctionPass *llvm::createStackProtectorPass(const TargetMachine *TM) {
return new StackProtector(TM);
}
StackProtector::SSPLayoutKind StackProtector::getSSPLayout(const AllocaInst *AI)
const {
StackProtector::SSPLayoutKind
StackProtector::getSSPLayout(const AllocaInst *AI) const {
return AI ? Layout.lookup(AI) : SSPLK_None;
}
@ -65,11 +64,11 @@ bool StackProtector::runOnFunction(Function &Fn) {
DT = getAnalysisIfAvailable<DominatorTree>();
TLI = TM->getTargetLowering();
if (!RequiresStackProtector()) return false;
if (!RequiresStackProtector())
return false;
Attribute Attr =
Fn.getAttributes().getAttribute(AttributeSet::FunctionIndex,
"stack-protector-buffer-size");
Attribute Attr = Fn.getAttributes().getAttribute(
AttributeSet::FunctionIndex, "stack-protector-buffer-size");
if (Attr.isStringAttribute())
Attr.getValueAsString().getAsInteger(10, SSPBufferSize);
@ -81,9 +80,10 @@ bool StackProtector::runOnFunction(Function &Fn) {
/// it is "large" ( >= ssp-buffer-size). In the case of a structure with
/// multiple arrays, this gets set if any of them is large.
bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
bool Strong, bool InStruct)
const {
if (!Ty) return false;
bool Strong,
bool InStruct) const {
if (!Ty)
return false;
if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
if (!AT->getElementType()->isIntegerTy(8)) {
// If we're on a non-Darwin platform or we're inside of a structure, don't
@ -107,11 +107,13 @@ bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
}
const StructType *ST = dyn_cast<StructType>(Ty);
if (!ST) return false;
if (!ST)
return false;
bool NeedsProtector = false;
for (StructType::element_iterator I = ST->element_begin(),
E = ST->element_end(); I != E; ++I)
E = ST->element_end();
I != E; ++I)
if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
// If the element is a protectable array and is large (>= SSPBufferSize)
// then we are done. If the protectable array is not large, then
@ -188,8 +190,8 @@ bool StackProtector::RequiresStackProtector() {
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
BasicBlock *BB = I;
for (BasicBlock::iterator
II = BB->begin(), IE = BB->end(); II != IE; ++II) {
for (BasicBlock::iterator II = BB->begin(), IE = BB->end(); II != IE;
++II) {
if (AllocaInst *AI = dyn_cast<AllocaInst>(II)) {
if (AI->isArrayAllocation()) {
// SSP-Strong: Enable protectors for any call to alloca, regardless
@ -259,7 +261,8 @@ static CallInst *FindPotentialTailCall(BasicBlock *BB, ReturnInst *RI,
const unsigned MaxSearch = 4;
bool NoInterposingChain = true;
for (BasicBlock::reverse_iterator I = llvm::next(BB->rbegin()), E = BB->rend();
for (BasicBlock::reverse_iterator I = llvm::next(BB->rbegin()),
E = BB->rend();
I != E && SearchCounter < MaxSearch; ++I) {
Instruction *Inst = &*I;
@ -289,7 +292,8 @@ static CallInst *FindPotentialTailCall(BasicBlock *BB, ReturnInst *RI,
// If we did not find a call see if we have an instruction that may create
// an interposing chain.
NoInterposingChain = NoInterposingChain && InstructionWillNotHaveChain(Inst);
NoInterposingChain =
NoInterposingChain && InstructionWillNotHaveChain(Inst);
// Increment max search.
SearchCounter++;
@ -318,9 +322,8 @@ static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
Constant *OffsetVal =
ConstantInt::get(Type::getInt32Ty(RI->getContext()), Offset);
StackGuardVar = ConstantExpr::getIntToPtr(OffsetVal,
PointerType::get(PtrTy,
AddressSpace));
StackGuardVar = ConstantExpr::getIntToPtr(
OffsetVal, PointerType::get(PtrTy, AddressSpace));
} else if (Trip.getOS() == llvm::Triple::OpenBSD) {
StackGuardVar = M->getOrInsertGlobal("__guard_local", PtrTy);
cast<GlobalValue>(StackGuardVar)
@ -352,7 +355,7 @@ bool StackProtector::InsertStackProtectors() {
AllocaInst *AI = 0; // Place on stack that stores the stack guard.
Value *StackGuardVar = 0; // The stack guard variable.
for (Function::iterator I = F->begin(), E = F->end(); I != E; ) {
for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
BasicBlock *BB = I++;
ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
if (!RI)
@ -360,8 +363,8 @@ bool StackProtector::InsertStackProtectors() {
if (!HasPrologue) {
HasPrologue = true;
SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, Trip, AI,
StackGuardVar);
SupportsSelectionDAGSP &=
CreatePrologue(F, M, RI, TLI, Trip, AI, StackGuardVar);
}
if (SupportsSelectionDAGSP) {