dead-stores.c revision a23157e6b9e2388edebd3d383dd7acfab6a4c0c0
1// RUN: clang -warn-dead-stores -verify %s
2
3void f1() {
4  int k, y;
5  int abc=1;
6  long idx=abc+3*5; // expected-warning {{value stored to variable is never used}}
7}
8
9void f2(void *b) {
10 char *c = (char*)b; // no-warning
11 char *d = b+1; // expected-warning {{value stored to variable is never used}}
12 printf("%s", c);
13}
14
15void f3() {
16  int r;
17  if ((r = f()) != 0) { // no-warning
18    int y = r; // no-warning
19    printf("the error is: %d\n", y);
20  }
21}
22
23void f4(int k) {
24
25  k = 1;
26
27  if (k)
28    f1();
29
30  k = 2;  // expected-warning {{value stored to variable is never used}}
31}
32
33void f5() {
34
35  int x = 4; // no-warning
36  int *p = &x; // expected-warning{{value stored to variable is never used}}
37
38}
39
40int f6() {
41
42  int x = 4;
43  ++x; // expected-warning{{value stored to variable is never used}}
44  return 1;
45}
46