summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/unreachable-code-path.c
diff options
context:
space:
mode:
authorTom Care <tcare@apple.com>2010-07-23 23:04:53 +0000
committerTom Care <tcare@apple.com>2010-07-23 23:04:53 +0000
commitcba9f517acfb0d7c3438eed71cf0db6229cd9671 (patch)
treed06d39031894e6c17d07be0cc3209bbd9fe89c25 /clang/test/Analysis/unreachable-code-path.c
parent28499f76c953a38bd8c8bcb634f25188bf02715f (diff)
downloadbcm5719-llvm-cba9f517acfb0d7c3438eed71cf0db6229cd9671.tar.gz
bcm5719-llvm-cba9f517acfb0d7c3438eed71cf0db6229cd9671.zip
Added an path-sensitive unreachable code checker to the experimental analyzer checks.
- Created a new class to do post-analysis - Updated several test cases with unreachable code to expect a warning - Added some general tests llvm-svn: 109286
Diffstat (limited to 'clang/test/Analysis/unreachable-code-path.c')
-rw-r--r--clang/test/Analysis/unreachable-code-path.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/clang/test/Analysis/unreachable-code-path.c b/clang/test/Analysis/unreachable-code-path.c
new file mode 100644
index 00000000000..cfe0408c3fe
--- /dev/null
+++ b/clang/test/Analysis/unreachable-code-path.c
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -analyze -analyzer-experimental-checks -analyzer-check-objc-mem -analyzer-check-dead-stores -verify -analyzer-opt-analyze-nested-blocks %s
+
+extern void foo(int a);
+
+void test(unsigned a) {
+ switch (a) {
+ a += 5; // expected-warning{{never executed}}
+ case 2:
+ a *= 10;
+ case 3:
+ a %= 2;
+ }
+ foo(a);
+}
+
+void test2(unsigned a) {
+ help:
+ if (a > 0)
+ return;
+ if (a == 0)
+ return;
+ foo(a); // expected-warning{{never executed}}
+ goto help;
+}
+
+void test3() {
+ int a = 5;
+
+ while (a > 1)
+ a -= 2;
+
+ if (a > 1) {
+ a = a + 56; // expected-warning{{never executed}}
+ }
+
+ 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) {
+ foo(c[0]);
+
+ if (!c) {
+ bar(1); // expected-warning{{never executed}}
+ }
+}
+
OpenPOWER on IntegriCloud