]> granicus.if.org Git - clang/commitdiff
[StaticAnalyzer] Fix false positives for unreachable code in macros.
authorDaniel Marjamaki <daniel.marjamaki@evidente.se>
Wed, 2 Aug 2017 08:26:56 +0000 (08:26 +0000)
committerDaniel Marjamaki <daniel.marjamaki@evidente.se>
Wed, 2 Aug 2017 08:26:56 +0000 (08:26 +0000)
Example:

#define MACRO(C)   if (C) { static int x; .. }
void foo() {
MACRO(0);
}

Differential Revision: https://reviews.llvm.org/D36141

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309799 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
test/Analysis/unreachable-code-path.c

index ccd8e9a18b00f42f885c8e3438ee1aa660ab3344..6f21e868b17424fa3079b4082b45fb5fa0a64f33 100644 (file)
@@ -112,7 +112,7 @@ void UnreachableCodeChecker::checkEndAnalysis(ExplodedGraph &G,
       continue;
 
     // Check for false positives
-    if (CB->size() > 0 && isInvalidPath(CB, *PM))
+    if (isInvalidPath(CB, *PM))
       continue;
 
     // It is good practice to always have a "default" label in a "switch", even
index ff58587be2da255124f4e6be9ad8c666f3680d15..effa4d9bfa6f4e72e42cb8d85749746c910f7a2f 100644 (file)
@@ -213,3 +213,13 @@ void macro(void) {
   RETURN(1); // no-warning
 }
 
+// Avoid FP when macro argument is known
+void writeSomething(int *x);
+#define MACRO(C)        \
+  if (!C) {             \
+    static int x;       \
+    writeSomething(&x); \
+  }
+void macro2(void) {
+  MACRO(1);
+}