diff options
author | George Karpenkov <ekarpenkov@apple.com> | 2017-05-24 00:29:12 +0000 |
---|---|---|
committer | George Karpenkov <ekarpenkov@apple.com> | 2017-05-24 00:29:12 +0000 |
commit | 018472c34ab877b96787d4317b95b2aa3aaafef0 (patch) | |
tree | 60e44392c48ad7912fd63f7067e08ac44c963a0c /llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp | |
parent | a793cfb441bb20e9c40428dcf92d8985839b237c (diff) | |
download | bcm5719-llvm-018472c34ab877b96787d4317b95b2aa3aaafef0.tar.gz bcm5719-llvm-018472c34ab877b96787d4317b95b2aa3aaafef0.zip |
Revert "Disable coverage opt-out for strong postdominator blocks."
This reverts commit 2ed06f05fc10869dd1239cff96fcdea2ee8bf4ef.
Buildbots do not like this on Linux.
llvm-svn: 303710
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp')
-rw-r--r-- | llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index 2329cbf4d6b..4bc0a713311 100644 --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -31,6 +31,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/EHPersonalities.h" +#include "llvm/Analysis/PostDominators.h" #include "llvm/IR/CFG.h" #include "llvm/IR/CallSite.h" #include "llvm/IR/DataLayout.h" @@ -168,6 +169,7 @@ public: void getAnalysisUsage(AnalysisUsage &AU) const override { AU.addRequired<DominatorTreeWrapperPass>(); + AU.addRequired<PostDominatorTreeWrapperPass>(); } private: @@ -365,8 +367,23 @@ static bool isFullDominator(const BasicBlock *BB, const DominatorTree *DT) { return true; } +// True if block has predecessors and it postdominates all of them. +static bool isFullPostDominator(const BasicBlock *BB, + const PostDominatorTree *PDT) { + if (pred_begin(BB) == pred_end(BB)) + return false; + + for (const BasicBlock *PRED : make_range(pred_begin(BB), pred_end(BB))) { + if (!PDT->dominates(BB, PRED)) + return false; + } + + return true; +} + static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB, const DominatorTree *DT, + const PostDominatorTree *PDT, const SanitizerCoverageOptions &Options) { // Don't insert coverage for unreachable blocks: we will never call // __sanitizer_cov() for them, so counting them in @@ -384,7 +401,7 @@ static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB, if (Options.NoPrune || &F.getEntryBlock() == BB) return true; - return !isFullDominator(BB, DT); + return !(isFullDominator(BB, DT) || isFullPostDominator(BB, PDT)); } bool SanitizerCoverageModule::runOnFunction(Function &F) { @@ -416,9 +433,11 @@ bool SanitizerCoverageModule::runOnFunction(Function &F) { const DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>(F).getDomTree(); + const PostDominatorTree *PDT = + &getAnalysis<PostDominatorTreeWrapperPass>(F).getPostDomTree(); for (auto &BB : F) { - if (shouldInstrumentBlock(F, &BB, DT, Options)) + if (shouldInstrumentBlock(F, &BB, DT, PDT, Options)) BlocksToInstrument.push_back(&BB); for (auto &Inst : BB) { if (Options.IndirectCalls) { @@ -700,6 +719,7 @@ INITIALIZE_PASS_BEGIN(SanitizerCoverageModule, "sancov", "ModulePass", false, false) INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) +INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass) INITIALIZE_PASS_END(SanitizerCoverageModule, "sancov", "SanitizerCoverage: TODO." "ModulePass", |