diff options
author | Jordan Rose <jordan_rose@apple.com> | 2013-11-08 01:15:30 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2013-11-08 01:15:30 +0000 |
commit | 236dbd25e77521977335b37f5fb915e5678b1195 (patch) | |
tree | 3f3234009465867f841429961863045aea4b339a /clang/lib | |
parent | ec7cea925e7687bf34ddc186d63ff734453612a8 (diff) | |
download | bcm5719-llvm-236dbd25e77521977335b37f5fb915e5678b1195.tar.gz bcm5719-llvm-236dbd25e77521977335b37f5fb915e5678b1195.zip |
[analyzer] Specialize "loop executed 0 times" for for-in and for-range loops.
The path note that says "Loop body executed 0 times" has been changed to
"Loop body skipped when range is empty" for C++11 for-range loops, and to
"Loop body skipped when collection is empty" for Objective-C for-in loops.
Part of <rdar://problem/14992886>
llvm-svn: 194234
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/BugReporter.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp index 6bb9ffcea92..1940fa79fda 100644 --- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -1629,6 +1629,10 @@ static const Stmt *getTerminatorCondition(const CFGBlock *B) { static const char StrEnteringLoop[] = "Entering loop body"; static const char StrLoopBodyZero[] = "Loop body executed 0 times"; +static const char StrLoopRangeEmpty[] = + "Loop body skipped when range is empty"; +static const char StrLoopCollectionEmpty[] = + "Loop body skipped when collection is empty"; static bool GenerateAlternateExtensivePathDiagnostic(PathDiagnostic& PD, @@ -1827,7 +1831,13 @@ GenerateAlternateExtensivePathDiagnostic(PathDiagnostic& PD, if (isJumpToFalseBranch(&*BE)) { if (!IsInLoopBody) { - str = StrLoopBodyZero; + if (isa<ObjCForCollectionStmt>(Term)) { + str = StrLoopCollectionEmpty; + } else if (isa<CXXForRangeStmt>(Term)) { + str = StrLoopRangeEmpty; + } else { + str = StrLoopBodyZero; + } } } else { str = StrEnteringLoop; @@ -2072,7 +2082,8 @@ static void simplifySimpleBranches(PathPieces &pieces) { PathDiagnosticEventPiece *EV = dyn_cast<PathDiagnosticEventPiece>(*NextI); if (EV) { StringRef S = EV->getString(); - if (S == StrEnteringLoop || S == StrLoopBodyZero) { + if (S == StrEnteringLoop || S == StrLoopBodyZero || + S == StrLoopCollectionEmpty || S == StrLoopRangeEmpty) { ++NextI; continue; } |