dead-stores.c revision 1a654b60ef40e84f3943cdb581795c4d4dae1e45
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 {{never read}}
7}
8
9void f2(void *b) {
10 char *c = (char*)b; // no-warning
11 char *d = b+1; // expected-warning {{never read}}
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 {{never read}}
31}
32
33void f5() {
34
35  int x = 4; // no-warning
36  int *p = &x; // expected-warning{{never read}}
37
38}
39
40int f6() {
41
42  int x = 4;
43  ++x; // expected-warning{{never read}}
44  return 1;
45}
46
47int f7(int *p) {
48  // This is allowed for defensive programming.
49  p = 0; // no-warning
50  return 1;
51}
52
53int f8(int *p) {
54  if (p = baz()) // expected-warning{{Although the value}}
55    return 1;
56  return 0;
57}
58
59