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