Artem Dergachev | 5fc1033 | 2018-02-10 01:55:23 +0000 | [diff] [blame] | 1 | // 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 Swiderski | 87b1bb6 | 2010-10-04 03:38:22 +0000 | [diff] [blame] | 12 | |
| 13 | class A { |
| 14 | public: |
| 15 | A() {} |
| 16 | A(int i) {} |
| 17 | }; |
| 18 | |
| 19 | class B : public virtual A { |
| 20 | public: |
| 21 | B() {} |
| 22 | B(int i) : A(i) {} |
| 23 | }; |
| 24 | |
| 25 | class C : public virtual A { |
| 26 | public: |
| 27 | C() {} |
| 28 | C(int i) : A(i) {} |
| 29 | }; |
| 30 | |
| 31 | class TestOrder : public C, public B, public A { |
| 32 | int i; |
| 33 | int& r; |
| 34 | public: |
| 35 | TestOrder(); |
| 36 | }; |
| 37 | |
| 38 | TestOrder::TestOrder() |
| 39 | : r(i), B(), i(), C() { |
| 40 | A a; |
| 41 | } |
| 42 | |
| 43 | class TestControlFlow { |
| 44 | int x, y, z; |
| 45 | public: |
| 46 | TestControlFlow(bool b); |
| 47 | }; |
| 48 | |
| 49 | TestControlFlow::TestControlFlow(bool b) |
| 50 | : y(b ? 0 : 1) |
| 51 | , x(0) |
| 52 | , z(y) { |
| 53 | int v; |
| 54 | } |
| 55 | |
Jordan Rose | 69d0aed | 2013-10-22 23:19:47 +0000 | [diff] [blame] | 56 | class 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 Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 63 | // CHECK: [B2 (ENTRY)] |
| 64 | // CHECK: Succs (1): B1 |
| 65 | // CHECK: [B1] |
Artem Dergachev | 5a281bb | 2018-02-10 02:18:04 +0000 | [diff] [blame] | 66 | // WARNINGS: 1: (CXXConstructExpr, class A) |
| 67 | // ANALYZER: 1: (CXXConstructExpr, A() (Base initializer), class A) |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 68 | // CHECK: 2: A([B1.1]) (Base initializer) |
Artem Dergachev | 5a281bb | 2018-02-10 02:18:04 +0000 | [diff] [blame] | 69 | // WARNINGS: 3: (CXXConstructExpr, class C) |
| 70 | // ANALYZER: 3: (CXXConstructExpr, C() (Base initializer), class C) |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 71 | // CHECK: 4: C([B1.3]) (Base initializer) |
Artem Dergachev | 5a281bb | 2018-02-10 02:18:04 +0000 | [diff] [blame] | 72 | // WARNINGS: 5: (CXXConstructExpr, class B) |
| 73 | // ANALYZER: 5: (CXXConstructExpr, B() (Base initializer), class B) |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 74 | // CHECK: 6: B([B1.5]) (Base initializer) |
Artem Dergachev | 5a281bb | 2018-02-10 02:18:04 +0000 | [diff] [blame] | 75 | // WARNINGS: 7: (CXXConstructExpr, class A) |
| 76 | // ANALYZER: 7: (CXXConstructExpr, A() (Base initializer), class A) |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 77 | // CHECK: 8: A([B1.7]) (Base initializer) |
Richard Smith | 301bc21 | 2016-05-19 01:39:10 +0000 | [diff] [blame] | 78 | // CHECK: 9: /*implicit*/(int)0 |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 79 | // 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 Dergachev | 5fc1033 | 2018-02-10 01:55:23 +0000 | [diff] [blame] | 83 | // WARNINGS: 14: (CXXConstructExpr, class A) |
| 84 | // ANALYZER: 14: (CXXConstructExpr, [B1.15], class A) |
Ted Kremenek | 72be32a | 2011-12-22 23:33:52 +0000 | [diff] [blame] | 85 | // 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 Rose | 69d0aed | 2013-10-22 23:19:47 +0000 | [diff] [blame] | 120 | // CHECK: [B2 (ENTRY)] |
| 121 | // CHECK: Succs (1): B1 |
| 122 | // CHECK: [B1] |
| 123 | // CHECK: 1: 2 |
| 124 | // CHECK: 2: 3 |
Artem Dergachev | 5a281bb | 2018-02-10 02:18:04 +0000 | [diff] [blame] | 125 | // 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 Rose | 69d0aed | 2013-10-22 23:19:47 +0000 | [diff] [blame] | 127 | // 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 |