2007-11-19 04:06:35 +08:00
|
|
|
// RUN: clang -warn-dead-stores -verify %s
|
2008-06-21 07:14:52 +08:00
|
|
|
// RUN: clang -checker-simple -verify %s
|
2007-11-19 14:38:23 +08:00
|
|
|
|
2008-04-14 23:56:17 +08:00
|
|
|
void f1() {
|
2007-11-19 04:06:35 +08:00
|
|
|
int k, y;
|
2008-03-19 15:31:52 +08:00
|
|
|
int abc=1;
|
2008-06-21 05:45:25 +08:00
|
|
|
long idx=abc+3*5; // expected-warning {{never read}}
|
2007-11-19 04:06:35 +08:00
|
|
|
}
|
2007-11-19 14:38:23 +08:00
|
|
|
|
2008-04-14 23:56:17 +08:00
|
|
|
void f2(void *b) {
|
2007-11-19 14:38:23 +08:00
|
|
|
char *c = (char*)b; // no-warning
|
2008-06-21 05:45:25 +08:00
|
|
|
char *d = b+1; // expected-warning {{never read}}
|
2007-11-19 14:38:23 +08:00
|
|
|
printf("%s", c);
|
|
|
|
}
|
2007-11-20 11:03:00 +08:00
|
|
|
|
2008-04-14 23:56:17 +08:00
|
|
|
void f3() {
|
2008-03-19 15:31:52 +08:00
|
|
|
int r;
|
|
|
|
if ((r = f()) != 0) { // no-warning
|
|
|
|
int y = r; // no-warning
|
|
|
|
printf("the error is: %d\n", y);
|
|
|
|
}
|
2007-11-20 11:03:00 +08:00
|
|
|
}
|
2008-04-14 23:56:17 +08:00
|
|
|
|
|
|
|
void f4(int k) {
|
|
|
|
|
|
|
|
k = 1;
|
|
|
|
|
|
|
|
if (k)
|
|
|
|
f1();
|
|
|
|
|
2008-06-21 05:45:25 +08:00
|
|
|
k = 2; // expected-warning {{never read}}
|
2008-04-14 23:56:17 +08:00
|
|
|
}
|
2008-04-16 02:37:29 +08:00
|
|
|
|
|
|
|
void f5() {
|
|
|
|
|
|
|
|
int x = 4; // no-warning
|
2008-06-21 05:45:25 +08:00
|
|
|
int *p = &x; // expected-warning{{never read}}
|
2008-04-16 02:37:29 +08:00
|
|
|
|
2008-05-06 07:12:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int f6() {
|
|
|
|
|
|
|
|
int x = 4;
|
2008-06-21 05:45:25 +08:00
|
|
|
++x; // expected-warning{{never read}}
|
2008-05-06 07:12:21 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2008-06-21 05:45:25 +08:00
|
|
|
|
|
|
|
int f7(int *p) {
|
|
|
|
// This is allowed for defensive programming.
|
|
|
|
p = 0; // no-warning
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int f8(int *p) {
|
|
|
|
if (p = baz()) // expected-warning{{Although the value}}
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|