Ted Kremenek | aa395ba | 2007-11-18 20:06:35 +0000 | [diff] [blame] | 1 | // RUN: clang -warn-dead-stores -verify %s |
Ted Kremenek | 8aefcbf | 2007-11-19 06:38:23 +0000 | [diff] [blame] | 2 | |
Ted Kremenek | 49a2fd2 | 2008-04-14 15:56:17 +0000 | [diff] [blame^] | 3 | void f1() { |
Ted Kremenek | aa395ba | 2007-11-18 20:06:35 +0000 | [diff] [blame] | 4 | int k, y; |
Ted Kremenek | 0fdf06e | 2008-03-19 07:31:52 +0000 | [diff] [blame] | 5 | int abc=1; |
6 | long idx=abc+3*5; // expected-warning {{value stored to variable is never used}} | ||||
Ted Kremenek | aa395ba | 2007-11-18 20:06:35 +0000 | [diff] [blame] | 7 | } |
Ted Kremenek | 8aefcbf | 2007-11-19 06:38:23 +0000 | [diff] [blame] | 8 | |
Ted Kremenek | 49a2fd2 | 2008-04-14 15:56:17 +0000 | [diff] [blame^] | 9 | void f2(void *b) { |
Ted Kremenek | 8aefcbf | 2007-11-19 06:38:23 +0000 | [diff] [blame] | 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 | } | ||||
Ted Kremenek | 74c43a0 | 2007-11-20 03:03:00 +0000 | [diff] [blame] | 14 | |
Ted Kremenek | 49a2fd2 | 2008-04-14 15:56:17 +0000 | [diff] [blame^] | 15 | void f3() { |
Ted Kremenek | 0fdf06e | 2008-03-19 07:31:52 +0000 | [diff] [blame] | 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 | } | ||||
Ted Kremenek | 74c43a0 | 2007-11-20 03:03:00 +0000 | [diff] [blame] | 21 | } |
Ted Kremenek | 49a2fd2 | 2008-04-14 15:56:17 +0000 | [diff] [blame^] | 22 | |
23 | void 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 | } |