blob: 49e72249e0371075b8168682480564371b000dab [file] [log] [blame]
Jordan Rose8d0f5282012-06-29 00:33:10 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpTraversal -std=c++11 %s | FileCheck -check-prefix=DFS %s
2
3int a();
4int b();
5int c();
6
7int work();
8
9void test(id input) {
10 if (a()) {
11 if (a())
12 b();
13 else
14 c();
15 } else {
16 if (b())
17 a();
18 else
19 c();
20 }
21
22 if (a())
23 work();
24}
25
26// This ordering assumes that true cases happen before the false cases.
27
28// BFS: 10 IfStmt
29// BFS-NEXT: 11 IfStmt
30// BFS-NEXT: 16 IfStmt
31// BFS-NEXT: 22 IfStmt
32// BFS-NEXT: 22 IfStmt
33// BFS-NEXT: 22 IfStmt
34// BFS-NEXT: 22 IfStmt
35// BFS-NEXT: --END PATH--
36// BFS-NEXT: --END PATH--
37// BFS-NEXT: --END PATH--
38// BFS-NEXT: --END PATH--
39// BFS-NEXT: --END PATH--
40// BFS-NEXT: --END PATH--
41// BFS-NEXT: --END PATH--
42// BFS-NEXT: --END PATH--
43
44// And this ordering assumes that false cases happen before the true cases.
45
46// DFS: 10 IfStmt
47// DFS-NEXT: 16 IfStmt
48// DFS-NEXT: 22 IfStmt
49// DFS-NEXT: --END PATH--
50// DFS-NEXT: --END PATH--
51// DFS-NEXT: 22 IfStmt
52// DFS-NEXT: --END PATH--
53// DFS-NEXT: --END PATH--
54// DFS-NEXT: 11 IfStmt
55// DFS-NEXT: 22 IfStmt
56// DFS-NEXT: --END PATH--
57// DFS-NEXT: --END PATH--
58// DFS-NEXT: 22 IfStmt
59// DFS-NEXT: --END PATH--
60// DFS-NEXT: --END PATH--
61
62
63void testLoops(id input) {
64 while (a()) {
65 work();
66 work();
67 work();
68 }
69
70 for (int i = 0; i != b(); ++i) {
71 work();
72 }
73
74 for (id x in input) {
75 work();
76 work();
77 work();
78 }
79
80 int z[] = {1,2,3};
81 for (int y : z) {
82 work();
83 work();
84 work();
85 }
86}
87
88// BFS: 64 WhileStmt
89// BFS: 70 ForStmt
90// BFS-NOT-NEXT: ObjCForCollectionStmt
91// BFS: 74 ObjCForCollectionStmt
92// BFS: 81 CXXForRangeStmt
93
94// DFS: 64 While
95// DFS-NEXT: 70 ForStmt
96// DFS-NEXT: 74 ObjCForCollectionStmt
97// DFS-NEXT: 81 CXXForRangeStmt