Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / missing-bind-temporary.cpp
blob3d1af469dc01c2b35990d35c13ffe771681a1a8e
1 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=debug.DumpCFG -std=c++14 -analyzer-config eagerly-assume=false %s > %t 2>&1
2 // RUN: FileCheck --input-file=%t %s
3 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=core,debug.ExprInspection -std=c++14 -verify -analyzer-config eagerly-assume=false %s
5 void clang_analyzer_eval(bool);
7 int global;
9 namespace variant_0 {
11 class A {
12 public:
13 ~A() { ++global; }
16 class B {
17 A a;
20 // CHECK: void foo(int)
21 // CHECK: [B1]
22 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
23 // CHECK-NEXT: 2: B i;
24 // CHECK-NEXT: 3: operator=
25 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
26 // CHECK-NEXT: 5: i
27 // CHECK-NEXT: 6: {} (CXXConstructExpr, [B1.7], [B1.8], B)
28 // CHECK-NEXT: 7: [B1.6] (BindTemporary)
29 // CHECK-NEXT: 8: [B1.7]
30 // CHECK-NEXT: 9: [B1.5] = [B1.8] (OperatorCall)
31 // CHECK-NEXT: 10: ~B() (Temporary object destructor)
32 // CHECK-NEXT: 11: [B1.2].~B() (Implicit destructor)
33 void foo(int) {
34 B i;
35 i = {};
38 void bar() {
39 global = 0;
40 foo(1);
41 clang_analyzer_eval(global == 2); // expected-warning{{TRUE}}
44 } // end namespace variant_0
46 namespace variant_1 {
48 class A {
49 public:
50 ~A() { ++global; }
53 class B {
54 A a;
57 // CHECK: template<> void foo<int>(int)
58 // CHECK: [B1]
59 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
60 // CHECK-NEXT: 2: B i;
61 // CHECK-NEXT: 3: operator=
62 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
63 // CHECK-NEXT: 5: i
64 // CHECK-NEXT: 6: {} (CXXConstructExpr, [B1.7], [B1.8], B)
65 // CHECK-NEXT: 7: [B1.6] (BindTemporary)
66 // CHECK-NEXT: 8: [B1.7]
67 // CHECK-NEXT: 9: [B1.5] = [B1.8] (OperatorCall)
68 // CHECK-NEXT: 10: ~B() (Temporary object destructor)
69 // CHECK-NEXT: 11: [B1.2].~B() (Implicit destructor)
70 template <typename T> void foo(T) {
71 B i;
72 i = {};
75 void bar() {
76 global = 0;
77 foo(1);
78 clang_analyzer_eval(global == 2); // expected-warning{{TRUE [debug.ExprInspection]}}
81 } // end namespace variant_1
83 namespace variant_2 {
84 // Making field 'a' in class 'B' public turns the class into an aggregate.
85 // In this case there is no constructor at {} - only an aggregate
86 // initialization. Aggregate initialization is unsupported for now.
88 class A {
89 public:
90 ~A() { ++global; }
93 class B {
94 public:
95 A a;
98 // CHECK: template<> void foo<int>(int)
99 // CHECK: [B1]
100 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
101 // CHECK-NEXT: 2: B i;
102 // CHECK-NEXT: 3: operator=
103 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
104 // CHECK-NEXT: 5: i
105 // CHECK-NEXT: 6: {}
106 // CHECK-NEXT: 7: {}
107 // CHECK-NEXT: 8: [B1.7] (BindTemporary)
108 // CHECK-NEXT: 9: [B1.8]
109 // CHECK-NEXT: 10: [B1.5] = [B1.9] (OperatorCall)
110 // CHECK-NEXT: 11: ~B() (Temporary object destructor)
111 // CHECK-NEXT: 12: [B1.2].~B() (Implicit destructor)
112 template <typename T> void foo(T) {
113 B i;
114 i = {};
117 void bar() {
118 global = 0;
119 foo(1);
120 // FIXME: Should be TRUE, i.e. we should call (and inline) two destructors.
121 clang_analyzer_eval(global == 2); // expected-warning{{UNKNOWN}}
124 } // end namespace variant_2