1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s 2 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 22} 23 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} 60