summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp8
-rw-r--r--clang/test/Analysis/unreachable-code-path.c7
2 files changed, 15 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();
diff --git a/clang/test/Analysis/unreachable-code-path.c b/clang/test/Analysis/unreachable-code-path.c
index 975c9887e45..4ddfb21f0a0 100644
--- a/clang/test/Analysis/unreachable-code-path.c
+++ b/clang/test/Analysis/unreachable-code-path.c
@@ -206,3 +206,10 @@ void test13(int i) {
int x = inlineFunction(i);
x && x < 10; // no-warning
}
+
+// Don't warn in a macro
+#define RETURN(X) do { return; } while (0)
+void macro(void) {
+ RETURN(1); // no-warning
+}
+
OpenPOWER on IntegriCloud