25
25
#include " llvm/IR/GlobalVariable.h"
26
26
#include " llvm/IR/IRBuilder.h"
27
27
#include " llvm/IR/InlineAsm.h"
28
- #include " llvm/IR/IntrinsicInst.h"
29
28
#include " llvm/IR/Intrinsics.h"
30
29
#include " llvm/IR/LLVMContext.h"
31
30
#include " llvm/IR/MDBuilder.h"
@@ -201,15 +200,13 @@ class SanitizerCoverageModule : public ModulePass {
201
200
ArrayRef<GetElementPtrInst *> GepTraceTargets);
202
201
void InjectTraceForSwitch (Function &F,
203
202
ArrayRef<Instruction *> SwitchTraceTargets);
204
- bool InjectCoverage (Function &F, ArrayRef<BasicBlock *> AllBlocks,
205
- bool IsLeafFunc = true );
203
+ bool InjectCoverage (Function &F, ArrayRef<BasicBlock *> AllBlocks);
206
204
GlobalVariable *CreateFunctionLocalArrayInSection (size_t NumElements,
207
205
Function &F, Type *Ty,
208
206
const char *Section);
209
207
GlobalVariable *CreatePCArray (Function &F, ArrayRef<BasicBlock *> AllBlocks);
210
208
void CreateFunctionLocalArrays (Function &F, ArrayRef<BasicBlock *> AllBlocks);
211
- void InjectCoverageAtBlock (Function &F, BasicBlock &BB, size_t Idx,
212
- bool IsLeafFunc = true );
209
+ void InjectCoverageAtBlock (Function &F, BasicBlock &BB, size_t Idx);
213
210
Function *CreateInitCallsForSections (Module &M, const char *InitFunctionName,
214
211
Type *Ty, const char *Section);
215
212
std::pair<GlobalVariable *, GlobalVariable *>
@@ -494,7 +491,6 @@ bool SanitizerCoverageModule::runOnFunction(Function &F) {
494
491
&getAnalysis<DominatorTreeWrapperPass>(F).getDomTree ();
495
492
const PostDominatorTree *PDT =
496
493
&getAnalysis<PostDominatorTreeWrapperPass>(F).getPostDomTree ();
497
- bool IsLeafFunc = true ;
498
494
499
495
for (auto &BB : F) {
500
496
if (shouldInstrumentBlock (F, &BB, DT, PDT, Options))
@@ -519,14 +515,10 @@ bool SanitizerCoverageModule::runOnFunction(Function &F) {
519
515
if (Options.TraceGep )
520
516
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&Inst))
521
517
GepTraceTargets.push_back (GEP);
522
- if (Options.StackDepth )
523
- if (isa<InvokeInst>(Inst) ||
524
- (isa<CallInst>(Inst) && !isa<IntrinsicInst>(Inst)))
525
- IsLeafFunc = false ;
526
- }
518
+ }
527
519
}
528
520
529
- InjectCoverage (F, BlocksToInstrument, IsLeafFunc );
521
+ InjectCoverage (F, BlocksToInstrument);
530
522
InjectCoverageForIndirectCalls (F, IndirCalls);
531
523
InjectTraceForCmp (F, CmpTraceTargets);
532
524
InjectTraceForSwitch (F, SwitchTraceTargets);
@@ -601,12 +593,11 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays(
601
593
}
602
594
603
595
bool SanitizerCoverageModule::InjectCoverage (Function &F,
604
- ArrayRef<BasicBlock *> AllBlocks,
605
- bool IsLeafFunc) {
596
+ ArrayRef<BasicBlock *> AllBlocks) {
606
597
if (AllBlocks.empty ()) return false ;
607
598
CreateFunctionLocalArrays (F, AllBlocks);
608
599
for (size_t i = 0 , N = AllBlocks.size (); i < N; i++)
609
- InjectCoverageAtBlock (F, *AllBlocks[i], i, IsLeafFunc );
600
+ InjectCoverageAtBlock (F, *AllBlocks[i], i);
610
601
return true ;
611
602
}
612
603
@@ -740,8 +731,7 @@ void SanitizerCoverageModule::InjectTraceForCmp(
740
731
}
741
732
742
733
void SanitizerCoverageModule::InjectCoverageAtBlock (Function &F, BasicBlock &BB,
743
- size_t Idx,
744
- bool IsLeafFunc) {
734
+ size_t Idx) {
745
735
BasicBlock::iterator IP = BB.getFirstInsertionPt ();
746
736
bool IsEntryBB = &BB == &F.getEntryBlock ();
747
737
DebugLoc EntryLoc;
@@ -780,7 +770,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
780
770
SetNoSanitizeMetadata (Load);
781
771
SetNoSanitizeMetadata (Store);
782
772
}
783
- if (Options.StackDepth && IsEntryBB && !IsLeafFunc ) {
773
+ if (Options.StackDepth && IsEntryBB) {
784
774
// Check stack depth. If it's the deepest so far, record it.
785
775
Function *GetFrameAddr =
786
776
Intrinsic::getDeclaration (F.getParent (), Intrinsic::frameaddress);
@@ -791,9 +781,7 @@ void SanitizerCoverageModule::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
791
781
auto IsStackLower = IRB.CreateICmpULT (FrameAddrInt, LowestStack);
792
782
auto ThenTerm = SplitBlockAndInsertIfThen (IsStackLower, &*IP, false );
793
783
IRBuilder<> ThenIRB (ThenTerm);
794
- auto Store = ThenIRB.CreateStore (FrameAddrInt, SanCovLowestStack);
795
- SetNoSanitizeMetadata (LowestStack);
796
- SetNoSanitizeMetadata (Store);
784
+ ThenIRB.CreateStore (FrameAddrInt, SanCovLowestStack);
797
785
}
798
786
}
799
787
0 commit comments