xref: /llvm-project/clang/test/Analysis/misc-ps-ranges.m (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -verify -fblocks %s
2
3// main's 'argc' argument is always > 0
4int main(int argc, char* argv[]) {
5  int *p = 0;
6
7  if (argc == 0)
8    *p = 1;
9
10  if (argc == 1)
11    return 1;
12
13  int x = 1;
14  int i;
15
16  for(i=1;i<argc;i++){
17    p = &x;
18  }
19
20  return *p; // no-warning
21}
22
23// PR 5969: the comparison of argc < 3 || argc > 4 should constraint the switch
24//  statement from having the 'default' branch taken.  This previously reported a false
25//  positive with the use of 'v'.
26
27int pr5969(int argc, char *argv[]) {
28
29  int v;
30
31  if ((argc < 3) || (argc > 4)) return 0;
32
33  switch(argc) {
34    case 3:
35      v = 33;
36      break;
37    case 4:
38      v = 44;
39      break;
40  }
41
42  return v; // no-warning
43}
44
45int pr5969_positive(int argc, char *argv[]) {
46
47  int v;
48
49  if ((argc < 3) || (argc > 4)) return 0;
50
51  switch(argc) {
52    case 3:
53      v = 33;
54      break;
55  }
56
57  return v; // expected-warning{{Undefined or garbage value returned to caller}}
58}
59