dead-stores.c revision fc7ff5540412f8003024e1b4940fb8408dff2ca6
1// RUN: clang -warn-dead-stores -verify %s &&
2// RUN: clang -checker-simple -warn-dead-stores -verify %s &&
3// RUN: clang -warn-dead-stores -checker-simple -verify %s
4
5
6void f1() {
7  int k, y;
8  int abc=1;
9  long idx=abc+3*5; // expected-warning {{never read}}
10}
11
12void f2(void *b) {
13 char *c = (char*)b; // no-warning
14 char *d = b+1; // expected-warning {{never read}}
15 printf("%s", c);
16}
17
18void f3() {
19  int r;
20  if ((r = f()) != 0) { // no-warning
21    int y = r; // no-warning
22    printf("the error is: %d\n", y);
23  }
24}
25
26void f4(int k) {
27
28  k = 1;
29
30  if (k)
31    f1();
32
33  k = 2;  // expected-warning {{never read}}
34}
35
36void f5() {
37
38  int x = 4; // no-warning
39  int *p = &x; // expected-warning{{never read}}
40
41}
42
43int f6() {
44
45  int x = 4;
46  ++x; // expected-warning{{never read}}
47  return 1;
48}
49
50int f7(int *p) {
51  // This is allowed for defensive programming.
52  p = 0; // no-warning
53  return 1;
54}
55
56int f8(int *p) {
57  if (p = baz()) // expected-warning{{Although the value}}
58    return 1;
59  return 0;
60}
61
62int f9() {
63  int x = 4;
64  x = x + 10; // expected-warning{{never read}}
65  return 1;
66}
67
68
69int f10() {
70  int x = 4;
71  x = 10 + x; // expected-warning{{never read}}
72  return 1;
73}
74
75int f11() {
76  int x = 4;
77  return ++x; // expected-warning{{never read}}
78}
79
80int f12a(int y) {
81  int x = y;  // expected-warning{{never read}}
82  return 1;
83}
84int f12b(int y) {
85  int x __attribute__((unused)) = y;  // no-warning
86  return 1;
87}
88
89