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);
10 // This variant of the code works correctly. Function foo() is not a template
11 // function. Note that there are two destructors within foo().
22 // CHECK: void foo(int)
24 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
25 // CHECK-NEXT: 2: B i;
26 // CHECK-NEXT: 3: operator=
27 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
29 // CHECK-NEXT: 6: {} (CXXConstructExpr, [B1.7], [B1.8], B)
30 // CHECK-NEXT: 7: [B1.6] (BindTemporary)
31 // CHECK-NEXT: 8: [B1.7]
32 // CHECK-NEXT: 9: [B1.5] = [B1.8] (OperatorCall)
33 // CHECK-NEXT: 10: ~B() (Temporary object destructor)
34 // CHECK-NEXT: 11: [B1.2].~B() (Implicit destructor)
43 clang_analyzer_eval(global
== 2); // expected-warning{{TRUE}}
46 } // end namespace variant_0
49 // Suddenly, if we turn foo() into a template, we are missing a
50 // CXXBindTemporaryExpr in the AST, and therefore we're missing a
51 // temporary destructor in the CFG.
62 // FIXME: Find the construction context for {} and enforce the temporary
64 // CHECK: template<> void foo<int>(int)
66 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
67 // CHECK-NEXT: 2: B i;
68 // CHECK-NEXT: 3: operator=
69 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
71 // CHECK-NEXT: 6: {} (CXXConstructExpr, B)
72 // CHECK-NEXT: 7: [B1.6]
73 // CHECK-NEXT: 8: [B1.5] = [B1.7] (OperatorCall)
74 // CHECK-NEXT: 9: [B1.2].~B() (Implicit destructor)
75 template <typename T
> void foo(T
) {
83 // FIXME: Should be TRUE, i.e. we should call (and inline) two destructors.
84 clang_analyzer_eval(global
== 2); // expected-warning{{UNKNOWN}}
87 } // end namespace variant_1
90 // Making field 'a' in class 'B' public turns the class into an aggregate.
91 // In this case there is no constructor at {} - only an aggregate
92 // initialization. Aggregate initialization is unsupported for now.
104 // CHECK: template<> void foo<int>(int)
106 // CHECK-NEXT: 1: (CXXConstructExpr, [B1.2], B)
107 // CHECK-NEXT: 2: B i;
108 // CHECK-NEXT: 3: operator=
109 // CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, FunctionToPointerDecay, B &(*)(B &&) noexcept)
113 // CHECK-NEXT: 8: [B1.7] (BindTemporary)
114 // CHECK-NEXT: 9: [B1.8]
115 // CHECK-NEXT: 10: [B1.5] = [B1.9] (OperatorCall)
116 // CHECK-NEXT: 11: ~B() (Temporary object destructor)
117 // CHECK-NEXT: 12: [B1.2].~B() (Implicit destructor)
118 template <typename T
> void foo(T
) {
126 // FIXME: Should be TRUE, i.e. we should call (and inline) two destructors.
127 clang_analyzer_eval(global
== 2); // expected-warning{{UNKNOWN}}
130 } // end namespace variant_2