dead-stores.c revision b497ebdce35c708e902db2d49183925a612b4914
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 extern int *baz(); 58 if (p = baz()) // expected-warning{{Although the value}} 59 return 1; 60 return 0; 61} 62 63int f9() { 64 int x = 4; 65 x = x + 10; // expected-warning{{never read}} 66 return 1; 67} 68 69 70int f10() { 71 int x = 4; 72 x = 10 + x; // expected-warning{{never read}} 73 return 1; 74} 75 76int f11() { 77 int x = 4; 78 return ++x; // expected-warning{{never read}} 79} 80 81int f12a(int y) { 82 int x = y; // expected-warning{{never read}} 83 return 1; 84} 85int f12b(int y) { 86 int x __attribute__((unused)) = y; // no-warning 87 return 1; 88} 89 90// Filed with PR 2630. This code should produce no warnings. 91int f13(void) 92{ 93 int a = 1; 94 int b, c = b = a + a; 95 96 if (b > 0) 97 return (0); 98 99 return (a + b + c); 100} 101 102// Filed with PR 2763. 103int f41(int count) { 104 int index, nextLineIndex; 105 for (index = 0; index < count; index = nextLineIndex+1) { 106 nextLineIndex = index+1; // no-warning 107 continue; 108 } 109 return index; 110} 111