mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-05 12:31:33 +00:00
- Make sure that we don't over-increment the iterator when going through the
basic blocks. - Minor code clean-up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59002 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
77cdf30742
commit
7205677a46
@ -123,14 +123,11 @@ bool StackProtector::InsertStackProtectors() {
|
|||||||
AllocaInst *AI = 0; // Place on stack that stores the stack guard.
|
AllocaInst *AI = 0; // Place on stack that stores the stack guard.
|
||||||
Constant *StackGuardVar = 0; // The stack guard variable.
|
Constant *StackGuardVar = 0; // The stack guard variable.
|
||||||
|
|
||||||
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
|
for (Function::iterator I = F->begin(), E = F->end(); I != E; ) {
|
||||||
BasicBlock *BB = I;
|
BasicBlock *BB = I;
|
||||||
|
|
||||||
if (isa<ReturnInst>(BB->getTerminator())) {
|
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
|
||||||
if (!FailBB) {
|
if (!FailBB) {
|
||||||
// Create the basic block to jump to when the guard check fails.
|
|
||||||
FailBB = CreateFailBB();
|
|
||||||
|
|
||||||
// Insert code into the entry block that stores the __stack_chk_guard
|
// Insert code into the entry block that stores the __stack_chk_guard
|
||||||
// variable onto the stack.
|
// variable onto the stack.
|
||||||
PointerType *PtrTy = PointerType::getUnqual(Type::Int8Ty);
|
PointerType *PtrTy = PointerType::getUnqual(Type::Int8Ty);
|
||||||
@ -146,11 +143,13 @@ bool StackProtector::InsertStackProtectors() {
|
|||||||
CallInst::
|
CallInst::
|
||||||
Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector_create),
|
Create(Intrinsic::getDeclaration(M, Intrinsic::stackprotector_create),
|
||||||
&Args[0], array_endof(Args), "", InsPt);
|
&Args[0], array_endof(Args), "", InsPt);
|
||||||
|
|
||||||
|
// Create the basic block to jump to when the guard check fails.
|
||||||
|
FailBB = CreateFailBB();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnInst *RI = cast<ReturnInst>(BB->getTerminator());
|
|
||||||
Function::iterator InsPt = BB; ++InsPt; // Insertion point for new BB.
|
Function::iterator InsPt = BB; ++InsPt; // Insertion point for new BB.
|
||||||
++I;
|
++I; // Skip to the next block so that we don't resplit the return block.
|
||||||
|
|
||||||
// Split the basic block before the return instruction.
|
// Split the basic block before the return instruction.
|
||||||
BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
|
BasicBlock *NewBB = BB->splitBasicBlock(RI, "SP_return");
|
||||||
@ -167,6 +166,8 @@ bool StackProtector::InsertStackProtectors() {
|
|||||||
AI, "", BB);
|
AI, "", BB);
|
||||||
ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, CI, LI1, "", BB);
|
ICmpInst *Cmp = new ICmpInst(CmpInst::ICMP_EQ, CI, LI1, "", BB);
|
||||||
BranchInst::Create(NewBB, FailBB, Cmp, BB);
|
BranchInst::Create(NewBB, FailBB, Cmp, BB);
|
||||||
|
} else {
|
||||||
|
++I;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user