2008-07-04 12:38:48 +08:00
|
|
|
// RUN: clang -warn-dead-stores -verify %s &&
|
|
|
|
// RUN: clang -checker-simple -warn-dead-stores -verify %s &&
|
2008-07-03 07:18:22 +08:00
|
|
|
// RUN: clang -warn-dead-stores -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) {
|
2008-08-05 08:07:51 +08:00
|
|
|
extern int *baz();
|
2008-06-21 05:45:25 +08:00
|
|
|
if (p = baz()) // expected-warning{{Although the value}}
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-24 05:16:38 +08:00
|
|
|
int f9() {
|
|
|
|
int x = 4;
|
|
|
|
x = x + 10; // expected-warning{{never read}}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int f10() {
|
|
|
|
int x = 4;
|
|
|
|
x = 10 + x; // expected-warning{{never read}}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-24 07:18:43 +08:00
|
|
|
int f11() {
|
|
|
|
int x = 4;
|
2008-10-15 13:23:41 +08:00
|
|
|
return x++; // expected-warning{{never read}}
|
2008-07-24 07:18:43 +08:00
|
|
|
}
|
|
|
|
|
2008-10-15 13:23:41 +08:00
|
|
|
int f11b() {
|
|
|
|
int x = 4;
|
|
|
|
return ++x; // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-25 12:47:34 +08:00
|
|
|
int f12a(int y) {
|
|
|
|
int x = y; // expected-warning{{never read}}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
int f12b(int y) {
|
|
|
|
int x __attribute__((unused)) = y; // no-warning
|
|
|
|
return 1;
|
|
|
|
}
|
2008-07-24 05:16:38 +08:00
|
|
|
|
2008-08-07 07:26:31 +08:00
|
|
|
// Filed with PR 2630. This code should produce no warnings.
|
|
|
|
int f13(void)
|
|
|
|
{
|
|
|
|
int a = 1;
|
|
|
|
int b, c = b = a + a;
|
|
|
|
|
|
|
|
if (b > 0)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (a + b + c);
|
|
|
|
}
|
|
|
|
|
2008-09-05 05:52:52 +08:00
|
|
|
// Filed with PR 2763.
|
2008-09-26 13:52:45 +08:00
|
|
|
int f14(int count) {
|
2008-09-05 05:52:52 +08:00
|
|
|
int index, nextLineIndex;
|
|
|
|
for (index = 0; index < count; index = nextLineIndex+1) {
|
|
|
|
nextLineIndex = index+1; // no-warning
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
2008-09-26 13:52:45 +08:00
|
|
|
|
|
|
|
// Test case for <rdar://problem/6248086>
|
|
|
|
void f15(unsigned x, unsigned y) {
|
|
|
|
int count = x * y; // no-warning
|
|
|
|
int z[count];
|
|
|
|
}
|
|
|
|
|
2008-09-27 06:58:57 +08:00
|
|
|
int f16(int x) {
|
|
|
|
x = x * 2;
|
2008-09-27 07:05:47 +08:00
|
|
|
x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{Although the value stored to 'x' is used}}
|
|
|
|
? 5 : 8;
|
2008-09-27 06:58:57 +08:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|