Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=basic -analyzer-constraints=range -verify -fblocks %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-constraints=range -verify -fblocks %s |
Ted Kremenek | 3a0fd13 | 2009-04-10 04:02:38 +0000 | [diff] [blame] | 3 | |
| 4 | // <rdar://problem/6776949> |
| 5 | // main's 'argc' argument is always > 0 |
| 6 | int main(int argc, char* argv[]) { |
| 7 | int *p = 0; |
| 8 | |
| 9 | if (argc == 0) |
| 10 | *p = 1; |
| 11 | |
| 12 | if (argc == 1) |
| 13 | return 1; |
| 14 | |
| 15 | int x = 1; |
| 16 | int i; |
| 17 | |
| 18 | for(i=1;i<argc;i++){ |
| 19 | p = &x; |
| 20 | } |
| 21 | |
| 22 | return *p; // no-warning |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 23 | } |
Ted Kremenek | 48569f9 | 2010-01-08 18:54:04 +0000 | [diff] [blame] | 24 | |
| 25 | // PR 5969: the comparison of argc < 3 || argc > 4 should constraint the switch |
| 26 | // statement from having the 'default' branch taken. This previously reported a false |
| 27 | // positive with the use of 'v'. |
| 28 | |
| 29 | int pr5969(int argc, char *argv[]) { |
| 30 | |
| 31 | int v; |
| 32 | |
| 33 | if ((argc < 3) || (argc > 4)) return 0; |
| 34 | |
| 35 | switch(argc) { |
| 36 | case 3: |
| 37 | v = 33; |
| 38 | break; |
| 39 | case 4: |
| 40 | v = 44; |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | return v; // no-warning |
| 45 | } |
| 46 | |
| 47 | int pr5969_positive(int argc, char *argv[]) { |
| 48 | |
| 49 | int v; |
| 50 | |
| 51 | if ((argc < 3) || (argc > 4)) return 0; |
| 52 | |
| 53 | switch(argc) { |
| 54 | case 3: |
| 55 | v = 33; |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | return v; // expected-warning{{Undefined or garbage value returned to caller}} |
| 60 | } |