summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
diff options
context:
space:
mode:
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>2016-10-18 13:16:53 +0000
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>2016-10-18 13:16:53 +0000
commitfa1bf447d904bdcbe8e78812d27f50c580e49c43 (patch)
tree8cc82060cfee320f80653c715400ce0c3834ccc9 /clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
parent6b6291aa9b25580a92b76abd8c8dad960ad75237 (diff)
downloadbcm5719-llvm-fa1bf447d904bdcbe8e78812d27f50c580e49c43.tar.gz
bcm5719-llvm-fa1bf447d904bdcbe8e78812d27f50c580e49c43.zip
alpha.core.UnreachableCode - don't warn about unreachable code inside macro
In macros, 'do {...} while (0)' is often used. Don't warn about the condition 0 when it is unreachable. Differential Revision: https://reviews.llvm.org/D25606 llvm-svn: 284477
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
index ff07a64d9b1..ccd8e9a18b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -147,6 +147,14 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G,
PathDiagnosticLocation DL;
SourceLocation SL;
if (const Stmt *S = getUnreachableStmt(CB)) {
+ // In macros, 'do {...} while (0)' is often used. Don't warn about the
+ // condition 0 when it is unreachable.
+ if (S->getLocStart().isMacroID())
+ if (const auto *I = dyn_cast<IntegerLiteral>(S))
+ if (I->getValue() == 0ULL)
+ if (const Stmt *Parent = PM->getParent(S))
+ if (isa<DoStmt>(Parent))
+ continue;
SR = S->getSourceRange();
DL = PathDiagnosticLocation::createBegin(S, B.getSourceManager(), LC);
SL = DL.asLocation();
OpenPOWER on IntegriCloud