aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Analysis/ReachableCode.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2014-03-21 06:02:36 +0000
committerTed Kremenek <kremenek@apple.com>2014-03-21 06:02:36 +0000
commit1421037ece1f3f4e20ab5e81b6931557218e9562 (patch)
treee3861c8a6940d865630c50adaa194f2bf8a13132 /clang/lib/Analysis/ReachableCode.cpp
parent7f2f9f402c0e05843697b2955ad719a27cf2cb99 (diff)
downloadllvm-1421037ece1f3f4e20ab5e81b6931557218e9562.zip
llvm-1421037ece1f3f4e20ab5e81b6931557218e9562.tar.gz
llvm-1421037ece1f3f4e20ab5e81b6931557218e9562.tar.bz2
[-Wunreachable-code] add a specialized diagnostic for unreachable increment expressions of loops.
llvm-svn: 204430
Diffstat (limited to 'clang/lib/Analysis/ReachableCode.cpp')
-rw-r--r--clang/lib/Analysis/ReachableCode.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Analysis/ReachableCode.cpp b/clang/lib/Analysis/ReachableCode.cpp
index 4220000..53e03de 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -529,6 +529,26 @@ void DeadCodeScan::reportDeadCode(const CFGBlock *B,
UK = reachable_code::UK_Return;
}
+ if (UK == reachable_code::UK_Other) {
+ // Check if the dead code is part of the "loop target" of
+ // a for/for-range loop. This is the block that contains
+ // the increment code.
+ if (const Stmt *LoopTarget = B->getLoopTarget()) {
+ SourceLocation Loc = LoopTarget->getLocStart();
+ SourceRange R1(Loc, Loc), R2;
+
+ if (const ForStmt *FS = dyn_cast<ForStmt>(LoopTarget)) {
+ const Expr *Inc = FS->getInc();
+ Loc = Inc->getLocStart();
+ R2 = Inc->getSourceRange();
+ }
+
+ CB.HandleUnreachable(reachable_code::UK_Loop_Increment,
+ Loc, SourceRange(Loc, Loc), R2);
+ return;
+ }
+ }
+
SourceRange R1, R2;
SourceLocation Loc = GetUnreachableLoc(S, R1, R2);
CB.HandleUnreachable(UK, Loc, R1, R2);