blob: 8d1039ddf34edfb91b985e70c8c48cf7df0ed5d9 [file] [log] [blame]
Artem Dergachev5fc10332018-02-10 01:55:23 +00001// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=false %s 2>&1 | FileCheck -check-prefixes=CHECK,WARNINGS %s
2// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=debug.DumpCFG -analyzer-config cfg-rich-constructors=true %s 2>&1 | FileCheck -check-prefixes=CHECK,ANALYZER %s
3
4// This file tests how we construct two different flavors of the Clang CFG -
5// the CFG used by the Sema analysis-based warnings and the CFG used by the
6// static analyzer. The difference in the behavior is checked via FileCheck
7// prefixes (WARNINGS and ANALYZER respectively). When introducing new analyzer
8// flags, no new run lines should be added - just these flags would go to the
9// respective line depending on where is it turned on and where is it turned
10// off. Feel free to add tests that test only one of the CFG flavors if you're
11// not sure how the other flavor is supposed to work in your case.
Marcin Swiderski87b1bb62010-10-04 03:38:22 +000012
13class A {
14public:
15 A() {}
16 A(int i) {}
17};
18
19class B : public virtual A {
20public:
21 B() {}
22 B(int i) : A(i) {}
23};
24
25class C : public virtual A {
26public:
27 C() {}
28 C(int i) : A(i) {}
29};
30
31class TestOrder : public C, public B, public A {
32 int i;
33 int& r;
34public:
35 TestOrder();
36};
37
38TestOrder::TestOrder()
39 : r(i), B(), i(), C() {
40 A a;
41}
42
43class TestControlFlow {
44 int x, y, z;
45public:
46 TestControlFlow(bool b);
47};
48
49TestControlFlow::TestControlFlow(bool b)
50 : y(b ? 0 : 1)
51 , x(0)
52 , z(y) {
53 int v;
54}
55
Jordan Rose69d0aed2013-10-22 23:19:47 +000056class TestDelegating {
57 int x, z;
58 public:
59 TestDelegating() : TestDelegating(2, 3) {}
60 TestDelegating(int x, int z) : x(x), z(z) {}
61};
62
Ted Kremenek72be32a2011-12-22 23:33:52 +000063// CHECK: [B2 (ENTRY)]
64// CHECK: Succs (1): B1
65// CHECK: [B1]
Artem Dergachev5a281bb2018-02-10 02:18:04 +000066// WARNINGS: 1: (CXXConstructExpr, class A)
67// ANALYZER: 1: (CXXConstructExpr, A() (Base initializer), class A)
Ted Kremenek72be32a2011-12-22 23:33:52 +000068// CHECK: 2: A([B1.1]) (Base initializer)
Artem Dergachev5a281bb2018-02-10 02:18:04 +000069// WARNINGS: 3: (CXXConstructExpr, class C)
70// ANALYZER: 3: (CXXConstructExpr, C() (Base initializer), class C)
Ted Kremenek72be32a2011-12-22 23:33:52 +000071// CHECK: 4: C([B1.3]) (Base initializer)
Artem Dergachev5a281bb2018-02-10 02:18:04 +000072// WARNINGS: 5: (CXXConstructExpr, class B)
73// ANALYZER: 5: (CXXConstructExpr, B() (Base initializer), class B)
Ted Kremenek72be32a2011-12-22 23:33:52 +000074// CHECK: 6: B([B1.5]) (Base initializer)
Artem Dergachev5a281bb2018-02-10 02:18:04 +000075// WARNINGS: 7: (CXXConstructExpr, class A)
76// ANALYZER: 7: (CXXConstructExpr, A() (Base initializer), class A)
Ted Kremenek72be32a2011-12-22 23:33:52 +000077// CHECK: 8: A([B1.7]) (Base initializer)
Richard Smith301bc212016-05-19 01:39:10 +000078// CHECK: 9: /*implicit*/(int)0
Ted Kremenek72be32a2011-12-22 23:33:52 +000079// CHECK: 10: i([B1.9]) (Member initializer)
80// CHECK: 11: this
81// CHECK: 12: [B1.11]->i
82// CHECK: 13: r([B1.12]) (Member initializer)
Artem Dergachev5fc10332018-02-10 01:55:23 +000083// WARNINGS: 14: (CXXConstructExpr, class A)
84// ANALYZER: 14: (CXXConstructExpr, [B1.15], class A)
Ted Kremenek72be32a2011-12-22 23:33:52 +000085// CHECK: 15: A a;
86// CHECK: Preds (1): B2
87// CHECK: Succs (1): B0
88// CHECK: [B0 (EXIT)]
89// CHECK: Preds (1): B1
90// CHECK: [B5 (ENTRY)]
91// CHECK: Succs (1): B4
92// CHECK: [B1]
93// CHECK: 1: [B4.4] ? [B2.1] : [B3.1]
94// CHECK: 2: y([B1.1]) (Member initializer)
95// CHECK: 3: this
96// CHECK: 4: [B1.3]->y
97// CHECK: 5: [B1.4] (ImplicitCastExpr, LValueToRValue, int)
98// CHECK: 6: z([B1.5]) (Member initializer)
99// CHECK: 7: int v;
100// CHECK: Preds (2): B2 B3
101// CHECK: Succs (1): B0
102// CHECK: [B2]
103// CHECK: 1: 0
104// CHECK: Preds (1): B4
105// CHECK: Succs (1): B1
106// CHECK: [B3]
107// CHECK: 1: 1
108// CHECK: Preds (1): B4
109// CHECK: Succs (1): B1
110// CHECK: [B4]
111// CHECK: 1: 0
112// CHECK: 2: x([B4.1]) (Member initializer)
113// CHECK: 3: b
114// CHECK: 4: [B4.3] (ImplicitCastExpr, LValueToRValue, _Bool)
115// CHECK: T: [B4.4] ? ... : ...
116// CHECK: Preds (1): B5
117// CHECK: Succs (2): B2 B3
118// CHECK: [B0 (EXIT)]
119// CHECK: Preds (1): B1
Jordan Rose69d0aed2013-10-22 23:19:47 +0000120// CHECK: [B2 (ENTRY)]
121// CHECK: Succs (1): B1
122// CHECK: [B1]
123// CHECK: 1: 2
124// CHECK: 2: 3
Artem Dergachev5a281bb2018-02-10 02:18:04 +0000125// WARNINGS: 3: [B1.1], [B1.2] (CXXConstructExpr, class TestDelegating)
126// ANALYZER: 3: [B1.1], [B1.2] (CXXConstructExpr, TestDelegating([B1.1], [B1.2]) (Delegating initializer), class TestDelegating)
Jordan Rose69d0aed2013-10-22 23:19:47 +0000127// CHECK: 4: TestDelegating([B1.3]) (Delegating initializer)
128// CHECK: Preds (1): B2
129// CHECK: Succs (1): B0
130// CHECK: [B0 (EXIT)]
131// CHECK: Preds (1): B1