blob: 90add22677f4d7ac18b3ed5329bb9913e7aceac0 [file] [log] [blame]
Ted Kremenekcdc3a892012-08-24 20:39:55 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s
Ted Kremenek3a0fd132009-04-10 04:02:38 +00002
3// <rdar://problem/6776949>
4// main's 'argc' argument is always > 0
5int main(int argc, char* argv[]) {
6 int *p = 0;
7
8 if (argc == 0)
9 *p = 1;
10
11 if (argc == 1)
12 return 1;
13
14 int x = 1;
15 int i;
16
17 for(i=1;i<argc;i++){
18 p = &x;
19 }
20
21 return *p; // no-warning
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000022}
Ted Kremenek48569f92010-01-08 18:54:04 +000023
24// PR 5969: the comparison of argc < 3 || argc > 4 should constraint the switch
25// statement from having the 'default' branch taken. This previously reported a false
26// positive with the use of 'v'.
27
28int pr5969(int argc, char *argv[]) {
29
30 int v;
31
32 if ((argc < 3) || (argc > 4)) return 0;
33
34 switch(argc) {
35 case 3:
36 v = 33;
37 break;
38 case 4:
39 v = 44;
40 break;
41 }
42
43 return v; // no-warning
44}
45
46int pr5969_positive(int argc, char *argv[]) {
47
48 int v;
49
50 if ((argc < 3) || (argc > 4)) return 0;
51
52 switch(argc) {
53 case 3:
54 v = 33;
55 break;
56 }
57
58 return v; // expected-warning{{Undefined or garbage value returned to caller}}
59}