Added some false positive checking to UnreachableCodeChecker
- Allowed reporting of dead macros
- Added path walking function to search for false positives in conditional statements
- Updated some affected tests
- Added some false positive test cases
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@109561 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Analysis/unreachable-code-path.c b/test/Analysis/unreachable-code-path.c
index e7e1d0b..00987dd 100644
--- a/test/Analysis/unreachable-code-path.c
+++ b/test/Analysis/unreachable-code-path.c
@@ -2,6 +2,8 @@
extern void foo(int a);
+// The first few tests are non-path specific - we should be able to find them
+
void test(unsigned a) {
switch (a) {
a += 5; // expected-warning{{never executed}}
@@ -23,7 +25,16 @@
goto help;
}
-void test3() {
+void test3(unsigned a) {
+ while(1);
+ if (a > 5) { // expected-warning{{never executed}}
+ return;
+ }
+}
+
+// These next tests are path-sensitive
+
+void test4() {
int a = 5;
while (a > 1)
@@ -36,13 +47,6 @@
foo(a);
}
-void test4(unsigned a) {
- while(1);
- if (a > 5) { // expected-warning{{never executed}}
- return;
- }
-}
-
extern void bar(char c);
void test5(const char *c) {
@@ -53,9 +57,34 @@
}
}
+// These next tests are false positives and should not generate warnings
+
void test6(const char *c) {
if (c) return;
if (!c) return;
__builtin_unreachable(); // no-warning
}
+// Compile-time constant false positives
+#define CONSTANT 0
+enum test_enum { Off, On };
+void test7() {
+ if (CONSTANT)
+ return; // no-warning
+
+ if (sizeof(int))
+ return; // no-warning
+
+ if (Off)
+ return; // no-warning
+}
+
+void test8() {
+ static unsigned a = 0;
+
+ if (a)
+ a = 123; // no-warning
+
+ a = 5;
+}
+