diff options
author | Ted Kremenek <kremenek@apple.com> | 2014-03-07 02:25:53 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2014-03-07 02:25:53 +0000 |
commit | 782f003c623b91e2ebc22136a4dce5a1905ff661 (patch) | |
tree | 8dbf29a5d0c62989dcf0b73c8d53dbd32debc73e /clang/lib/Analysis/ReachableCode.cpp | |
parent | c10830b3082ce237730ea4c9e5401706d5af0974 (diff) | |
download | bcm5719-llvm-782f003c623b91e2ebc22136a4dce5a1905ff661.tar.gz bcm5719-llvm-782f003c623b91e2ebc22136a4dce5a1905ff661.zip |
[-Wunreachable-code] Correctly expand artificial reachability to pruned '&&' and '||' branches involving configuration values.
llvm-svn: 203194
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r-- | clang/lib/Analysis/ReachableCode.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp index fa31dc1b068..09abcc9b7dc 100644 --- a/clang/lib/Analysis/ReachableCode.cpp +++ b/clang/lib/Analysis/ReachableCode.cpp @@ -459,9 +459,13 @@ static bool isConfigurationValue(const Stmt *S) { /// Returns true if we should always explore all successors of a block. static bool shouldTreatSuccessorsAsReachable(const CFGBlock *B) { - if (const Stmt *Term = B->getTerminator()) + if (const Stmt *Term = B->getTerminator()) { if (isa<SwitchStmt>(Term)) return true; + // Specially handle '||' and '&&'. + if (isa<BinaryOperator>(Term)) + return isConfigurationValue(Term); + } return isConfigurationValue(B->getTerminatorCondition()); } @@ -491,9 +495,9 @@ unsigned ScanReachableFromBlock(const CFGBlock *Start, // and that we should forge ahead and explore those branches anyway. // This allows us to potentially uncover some "always unreachable" code // within the "sometimes unreachable" code. - bool TreatAllSuccessorsAsReachable = shouldTreatSuccessorsAsReachable(item); - // Look at the successors and mark then reachable. + Optional<bool> TreatAllSuccessorsAsReachable; + for (CFGBlock::const_succ_iterator I = item->succ_begin(), E = item->succ_end(); I != E; ++I) { const CFGBlock *B = *I; @@ -502,7 +506,11 @@ unsigned ScanReachableFromBlock(const CFGBlock *Start, if (!UB) break; - if (TreatAllSuccessorsAsReachable) { + if (!TreatAllSuccessorsAsReachable.hasValue()) + TreatAllSuccessorsAsReachable = + shouldTreatSuccessorsAsReachable(item); + + if (TreatAllSuccessorsAsReachable.getValue()) { B = UB; break; } |