diff options
author | DeLesley Hutchins <delesley@google.com> | 2012-09-21 17:57:00 +0000 |
---|---|---|
committer | DeLesley Hutchins <delesley@google.com> | 2012-09-21 17:57:00 +0000 |
commit | d2f388299153d80cbe5ffaaed8a882b59a1b59bc (patch) | |
tree | 57d6947c8743be25f8527ff24cb7d9157523f93c /lib/Analysis/ThreadSafety.cpp | |
parent | 938869941e5a01049fb301fbf82f3caa4c7efa09 (diff) |
Thread-safety analysis: better handling of unreachable blocks. Fixes a bug
where a call to function marked 'noreturn' is followed by unreachable
implicit destructor calls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164394 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ThreadSafety.cpp')
-rw-r--r-- | lib/Analysis/ThreadSafety.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/lib/Analysis/ThreadSafety.cpp b/lib/Analysis/ThreadSafety.cpp index d9ab61e753..bc8a3c0d1a 100644 --- a/lib/Analysis/ThreadSafety.cpp +++ b/lib/Analysis/ThreadSafety.cpp @@ -892,6 +892,7 @@ struct CFGBlockInfo { SourceLocation EntryLoc; // Location of first statement in block SourceLocation ExitLoc; // Location of last statement in block. unsigned EntryIndex; // Used to replay contexts later + bool Reachable; // Is this block reachable? const FactSet &getSet(CFGBlockSide Side) const { return Side == CBS_Entry ? EntrySet : ExitSet; @@ -902,7 +903,7 @@ struct CFGBlockInfo { private: CFGBlockInfo(LocalVarContext EmptyCtx) - : EntryContext(EmptyCtx), ExitContext(EmptyCtx) + : EntryContext(EmptyCtx), ExitContext(EmptyCtx), Reachable(false) { } public: @@ -2183,6 +2184,9 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { PostOrderCFGView *SortedGraph = AC.getAnalysis<PostOrderCFGView>(); PostOrderCFGView::CFGBlockSet VisitedBlocks(CFGraph); + // Mark entry block as reachable + BlockInfo[CFGraph->getEntry().getBlockID()].Reachable = true; + // Compute SSA names for local variables LocalVarMap.traverseCFG(CFGraph, SortedGraph, BlockInfo); @@ -2270,10 +2274,16 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { if (*PI == 0 || !VisitedBlocks.alreadySet(*PI)) continue; + int PrevBlockID = (*PI)->getBlockID(); + CFGBlockInfo *PrevBlockInfo = &BlockInfo[PrevBlockID]; + // Ignore edges from blocks that can't return. - if ((*PI)->hasNoReturnElement()) + if ((*PI)->hasNoReturnElement() || !PrevBlockInfo->Reachable) continue; + // Okay, we can reach this block from the entry. + CurrBlockInfo->Reachable = true; + // If the previous block ended in a 'continue' or 'break' statement, then // a difference in locksets is probably due to a bug in that block, rather // than in some other predecessor. In that case, keep the other @@ -2285,8 +2295,7 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { } } - int PrevBlockID = (*PI)->getBlockID(); - CFGBlockInfo *PrevBlockInfo = &BlockInfo[PrevBlockID]; + FactSet PrevLockset; getEdgeLockset(PrevLockset, PrevBlockInfo->ExitSet, *PI, CurrBlock); @@ -2300,6 +2309,10 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { } } + // Skip rest of block if it's not reachable. + if (!CurrBlockInfo->Reachable) + continue; + // Process continue and break blocks. Assume that the lockset for the // resulting block is unaffected by any discrepancies in them. for (unsigned SpecialI = 0, SpecialN = SpecialBlocks.size(); @@ -2386,23 +2399,13 @@ void ThreadSafetyAnalyzer::runAnalysis(AnalysisDeclContext &AC) { } } + CFGBlockInfo *Initial = &BlockInfo[CFGraph->getEntry().getBlockID()]; + CFGBlockInfo *Final = &BlockInfo[CFGraph->getExit().getBlockID()]; - // Check to make sure that the exit block is reachable - bool ExitUnreachable = true; - for (CFGBlock::const_pred_iterator PI = CFGraph->getExit().pred_begin(), - PE = CFGraph->getExit().pred_end(); PI != PE; ++PI) { - if (!(*PI)->hasNoReturnElement()) { - ExitUnreachable = false; - break; - } - } // Skip the final check if the exit block is unreachable. - if (ExitUnreachable) + if (!Final->Reachable) return; - CFGBlockInfo *Initial = &BlockInfo[CFGraph->getEntry().getBlockID()]; - CFGBlockInfo *Final = &BlockInfo[CFGraph->getExit().getBlockID()]; - // FIXME: Should we call this function for all blocks which exit the function? intersectAndWarn(Initial->EntrySet, Final->ExitSet, Final->ExitLoc, |