1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
// RUN: %clang_analyze_cc1 -analyzer-checker=debug.DumpCFG -triple x86_64-apple-darwin12 -analyzer-config cfg-temporary-dtors=true -std=c++11 %s > %t 2>&1
// RUN: FileCheck --input-file=%t %s
class C {
public:
C();
C(C *);
static C get();
};
typedef __typeof(sizeof(int)) size_t;
void *operator new(size_t size, void *placement);
namespace operator_new {
// CHECK: void operatorNewWithConstructor()
// CHECK: 1: CFGNewAllocator(C *)
// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
// CHECK-NEXT: 3: new C([B1.2])
void operatorNewWithConstructor() {
new C();
}
// CHECK: void operatorNewWithConstructorWithOperatorNewWithContstructor()
// CHECK: 1: CFGNewAllocator(C *)
// CHECK-NEXT: 2: CFGNewAllocator(C *)
// CHECK-NEXT: 3: (CXXConstructExpr, [B1.4], class C)
// CHECK-NEXT: 4: new C([B1.3])
// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, [B1.6], class C)
// CHECK-NEXT: 6: new C([B1.5])
void operatorNewWithConstructorWithOperatorNewWithContstructor() {
new C(new C());
}
// CHECK: void operatorPlacementNewWithConstructorWithinPlacementArgument()
// CHECK: 1: CFGNewAllocator(C *)
// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
// CHECK-NEXT: 3: new C([B1.2])
// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, BitCast, void *)
// CHECK-NEXT: 5: CFGNewAllocator(C *)
// CHECK-NEXT: 6: (CXXConstructExpr, [B1.7], class C)
// CHECK-NEXT: 7: new ([B1.4]) C([B1.6])
void operatorPlacementNewWithConstructorWithinPlacementArgument() {
new (new C()) C();
}
} // namespace operator_new
namespace decl_stmt {
// CHECK: void simpleVariable()
// CHECK: 1: (CXXConstructExpr, [B1.2], class C)
// CHECK-NEXT: 2: C c;
void simpleVariable() {
C c;
}
// CHECK: void simpleVariableWithBraces()
// CHECK: 1: {} (CXXConstructExpr, [B1.2], class C)
// CHECK-NEXT: 2: C c{};
void simpleVariableWithBraces() {
C c{};
}
// CHECK: void simpleVariableWithConstructorArgument()
// CHECK: 1: 0
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, [B1.4], class C)
// CHECK-NEXT: 4: C c(0);
void simpleVariableWithConstructorArgument() {
C c(0);
}
// CHECK: void simpleVariableWithOperatorNewInConstructorArgument()
// CHECK: 1: CFGNewAllocator(C *)
// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
// CHECK-NEXT: 3: new C([B1.2])
// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.5], class C)
// CHECK-NEXT: 5: C c(new C());
void simpleVariableWithOperatorNewInConstructorArgument() {
C c(new C());
}
// CHECK: void simpleVariableWithOperatorNewInBraces()
// CHECK: 1: CFGNewAllocator(C *)
// CHECK-NEXT: 2: (CXXConstructExpr, [B1.3], class C)
// CHECK-NEXT: 3: new C([B1.2])
// CHECK-NEXT: 4: {[B1.3]} (CXXConstructExpr, [B1.5], class C)
// CHECK-NEXT: 5: C c{new C()};
void simpleVariableWithOperatorNewInBraces() {
C c{new C()};
}
// TODO: Should find construction target here.
// CHECK: void simpleVariableInitializedByValue()
// CHECK: 1: C::get
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class C (*)(void))
// CHECK-NEXT: 3: [B1.2]()
// CHECK-NEXT: 4: [B1.3]
// CHECK-NEXT: 5: [B1.4] (CXXConstructExpr, class C)
// CHECK-NEXT: 6: C c = C::get();
void simpleVariableInitializedByValue() {
C c = C::get();
}
// TODO: Should find construction target here.
// CHECK: void referenceVariableWithConstructor()
// CHECK: 1: 0
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NullToPointer, class C *)
// CHECK-NEXT: 3: [B1.2] (CXXConstructExpr, const class C)
// CHECK-NEXT: 4: [B1.3]
// CHECK-NEXT: 5: const C &c(0);
void referenceVariableWithConstructor() {
const C &c(0);
}
// TODO: Should find construction target here.
// CHECK: void referenceVariableWithInitializer()
// CHECK: 1: C() (CXXConstructExpr, class C)
// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class C)
// CHECK-NEXT: 3: [B1.2]
// CHECK-NEXT: 4: const C &c = C();
void referenceVariableWithInitializer() {
const C &c = C();
}
} // end namespace decl_stmt
|