blob: 338465a4e445fc883c3a34123a27da8096b472bf [file] [log] [blame]
Ted Kremenekaa395ba2007-11-18 20:06:35 +00001// RUN: clang -warn-dead-stores -verify %s
Ted Kremenek8aefcbf2007-11-19 06:38:23 +00002
Ted Kremenek49a2fd22008-04-14 15:56:17 +00003void f1() {
Ted Kremenekaa395ba2007-11-18 20:06:35 +00004 int k, y;
Ted Kremenek0fdf06e2008-03-19 07:31:52 +00005 int abc=1;
6 long idx=abc+3*5; // expected-warning {{value stored to variable is never used}}
Ted Kremenekaa395ba2007-11-18 20:06:35 +00007}
Ted Kremenek8aefcbf2007-11-19 06:38:23 +00008
Ted Kremenek49a2fd22008-04-14 15:56:17 +00009void f2(void *b) {
Ted Kremenek8aefcbf2007-11-19 06:38:23 +000010 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}
Ted Kremenek74c43a02007-11-20 03:03:00 +000014
Ted Kremenek49a2fd22008-04-14 15:56:17 +000015void f3() {
Ted Kremenek0fdf06e2008-03-19 07:31:52 +000016 int r;
17 if ((r = f()) != 0) { // no-warning
18 int y = r; // no-warning
19 printf("the error is: %d\n", y);
20 }
Ted Kremenek74c43a02007-11-20 03:03:00 +000021}
Ted Kremenek49a2fd22008-04-14 15:56:17 +000022
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}