danielmarjamaki created this revision.
Herald added a subscriber: whisperity.

This fixes a FP. Without the fix, the checker says that "static int x;" is 
unreachable.


Repository:
  rL LLVM

https://reviews.llvm.org/D36141

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


Index: test/Analysis/unreachable-code-path.c
===================================================================
--- test/Analysis/unreachable-code-path.c
+++ test/Analysis/unreachable-code-path.c
@@ -213,3 +213,13 @@
   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);
+}
Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -112,7 +112,7 @@
       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: test/Analysis/unreachable-code-path.c
===================================================================
--- test/Analysis/unreachable-code-path.c
+++ test/Analysis/unreachable-code-path.c
@@ -213,3 +213,13 @@
   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);
+}
Index: lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UnreachableCodeChecker.cpp
@@ -112,7 +112,7 @@
       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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D36141: [StaticA... Daniel Marjamäki via Phabricator via cfe-commits

Reply via email to