1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,alpha.deadcode.UnreachableCode -verify -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
) {
9 a
+= 5; // expected-warning{{never executed}}
18 void test2(unsigned a
) {
24 foo(a
); // expected-warning{{never executed}}
28 void test3(unsigned a
) {
30 if (a
> 5) { // expected-warning{{never executed}}
35 // These next tests are path-sensitive
44 a
= a
+ 56; // expected-warning{{never executed}}
50 extern void bar(char c
);
52 void test5(const char *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
) {
65 __builtin_unreachable(); // no-warning
66 __builtin_assume(0); // no-warning
69 // Compile-time constant false positives
71 enum test_enum
{ Off
, On
};
84 static unsigned a
= 0;
87 a
= 123; // no-warning
92 // Check for bugs where multiple statements are reported
93 void test9(unsigned a
) {
95 if (a
) // expected-warning{{never executed}}
96 foo(a
+ 5); // no-warning
107 // Tests from flow-sensitive version
111 goto e
; // expected-warning {{never executed}}
115 goto b
; // expected-warning {{never executed}}
116 goto a
; // expected-warning {{never executed}}
127 // test11: we can actually end up in the default case, even if it is not
128 // obvious: there might be something wrong with the given argument.
129 enum foobar
{ FOO
, BAR
};
130 extern void error(void);
131 void test11(enum foobar fb
) {
138 error(); // no-warning
140 error(); // expected-warning {{never executed}}
144 void inlined(int condition
) {
146 foo(5); // no-warning
152 void testInlined(void) {
153 extern int coin(void);
158 foo(5); // expected-warning {{never executed}}
163 // Don't warn about unreachable VarDecl.
165 void varDecl1(int X
) {
167 int A
; // No warning here.
176 void varDecl2(int X
) {
178 int A
=1; // expected-warning {{never executed}}
188 // Ensure that ExplodedGraph and unoptimized CFG match.
192 break; // not unreachable
199 // Don't merge return nodes in ExplodedGraph unless they are same.
201 static int inlineFunction(const int i
) {
207 int x
= inlineFunction(i
);
208 x
&& x
< 10; // no-warning
211 // Don't warn in a macro
212 #define RETURN(X) do { return; } while (0)
214 RETURN(1); // no-warning
217 // Avoid FP when macro argument is known
218 void writeSomething(int *x
);
222 writeSomething(&x); \