aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/traversal-algorithm.mm
blob: 49e72249e0371075b8168682480564371b000dab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpTraversal -std=c++11 %s | FileCheck -check-prefix=DFS %s

int a();
int b();
int c();

int work();

void test(id input) {
  if (a()) {
    if (a())
      b();
    else
      c();
  } else {
    if (b())
      a();
    else
      c();
  }

  if (a())
    work();
}

// This ordering assumes that true cases happen before the false cases.

// BFS: 10 IfStmt
// BFS-NEXT: 11 IfStmt
// BFS-NEXT: 16 IfStmt
// BFS-NEXT: 22 IfStmt
// BFS-NEXT: 22 IfStmt
// BFS-NEXT: 22 IfStmt
// BFS-NEXT: 22 IfStmt
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--
// BFS-NEXT: --END PATH--

// And this ordering assumes that false cases happen before the true cases.

// DFS: 10 IfStmt
// DFS-NEXT: 16 IfStmt
// DFS-NEXT: 22 IfStmt
// DFS-NEXT: --END PATH--
// DFS-NEXT: --END PATH--
// DFS-NEXT: 22 IfStmt
// DFS-NEXT: --END PATH--
// DFS-NEXT: --END PATH--
// DFS-NEXT: 11 IfStmt
// DFS-NEXT: 22 IfStmt
// DFS-NEXT: --END PATH--
// DFS-NEXT: --END PATH--
// DFS-NEXT: 22 IfStmt
// DFS-NEXT: --END PATH--
// DFS-NEXT: --END PATH--


void testLoops(id input) {
  while (a()) {
    work();
    work();
    work();
  }

  for (int i = 0; i != b(); ++i) {
    work();
  }

  for (id x in input) {
    work();
    work();
    work();
  }

  int z[] = {1,2,3};
  for (int y : z) {
    work();
    work();
    work();
  }
}

// BFS: 64 WhileStmt
// BFS: 70 ForStmt
// BFS-NOT-NEXT: ObjCForCollectionStmt
// BFS: 74 ObjCForCollectionStmt
// BFS: 81 CXXForRangeStmt

// DFS: 64 While
// DFS-NEXT: 70 ForStmt
// DFS-NEXT: 74 ObjCForCollectionStmt
// DFS-NEXT: 81 CXXForRangeStmt