[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / test / Analysis / unreachable-code-path.c
blob52e6d3df2c015d8daf61c66a767a76eb9d924b4c
1 // RUN: %clang_cc1 -analyze -analyzer-checker=core.experimental.UnreachableCode -analyzer-check-objc-mem -analyzer-checker=core.DeadStores -verify -analyzer-opt-analyze-nested-blocks -Wno-unused-value %s
3 extern void foo(int a);
5 // The first few tests are non-path specific - we should be able to find them
7 void test(unsigned a) {
8 switch (a) {
9 a += 5; // expected-warning{{never executed}}
10 case 2:
11 a *= 10;
12 case 3:
13 a %= 2;
15 foo(a);
18 void test2(unsigned a) {
19 help:
20 if (a > 0)
21 return;
22 if (a == 0)
23 return;
24 foo(a); // expected-warning{{never executed}}
25 goto help;
28 void test3(unsigned a) {
29 while(1);
30 if (a > 5) { // expected-warning{{never executed}}
31 return;
35 // These next tests are path-sensitive
37 void test4() {
38 int a = 5;
40 while (a > 1)
41 a -= 2;
43 if (a > 1) {
44 a = a + 56; // expected-warning{{never executed}}
47 foo(a);
50 extern void bar(char c);
52 void test5(const char *c) {
53 foo(c[0]);
55 if (!c) {
56 bar(1); // expected-warning{{never executed}}
60 // These next tests are false positives and should not generate warnings
62 void test6(const char *c) {
63 if (c) return;
64 if (!c) return;
65 __builtin_unreachable(); // no-warning
68 // Compile-time constant false positives
69 #define CONSTANT 0
70 enum test_enum { Off, On };
71 void test7() {
72 if (CONSTANT)
73 return; // no-warning
75 if (sizeof(int))
76 return; // no-warning
78 if (Off)
79 return; // no-warning
82 void test8() {
83 static unsigned a = 0;
85 if (a)
86 a = 123; // no-warning
88 a = 5;
91 // Check for bugs where multiple statements are reported
92 void test9(unsigned a) {
93 switch (a) {
94 if (a) // expected-warning{{never executed}}
95 foo(a + 5); // no-warning
96 else // no-warning
97 foo(a); // no-warning
98 case 1:
99 case 2:
100 break;
101 default:
102 break;
106 // Tests from flow-sensitive version
107 void test10() {
108 goto c;
110 goto e; // expected-warning {{never executed}}
111 c: ;
112 int i;
113 return;
114 goto b; // expected-warning {{never executed}}
115 goto a; // expected-warning {{never executed}}
117 i = 1; // no-warning
119 i = 2; // no-warning
120 goto f;
122 goto d;
123 f: ;