-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPODType03.qll
More file actions
131 lines (123 loc) · 3.91 KB
/
PODType03.qll
File metadata and controls
131 lines (123 loc) · 3.91 KB
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
129
130
131
/**
* Provides predicates to determine whether a type is an aggregate or POD
* (Plain Old Data), as defined by C++03.
*/
import cpp
/**
* Holds if `t` is a scalar type, according to the rules specified in
* C++03 3.9(10):
*
* Arithmetic types (3.9.1), enumeration types, pointer types, and
* pointer to member types (3.9.2), and cv-qualified versions of these
* types (3.9.3) are collectively called scalar types.
*/
predicate isScalarType03(Type t) {
exists(Type ut | ut = t.getUnderlyingType() |
ut instanceof ArithmeticType or
ut instanceof Enum or
ut instanceof FunctionPointerType or
ut instanceof PointerToMemberType or
ut instanceof PointerType or
isScalarType03(ut.(SpecifiedType).getUnspecifiedType())
)
}
/**
* Holds if `c` is an aggregate class, according to the rules specified in
* C++03 8.5.1(1):
*
* An aggregate [class] is ... a class (clause 9) with no user-declared
* constructors (12.1), no private or protected non-static data members
* (clause 11), no base classes (clause 10), and no virtual functions
* (10.3).
*/
predicate isAggregateClass03(Class c) {
not c instanceof TemplateClass and
not exists(Constructor cons |
cons.getDeclaringType() = c and
not cons.isCompilerGenerated()
) and
not exists(Variable v |
v.getDeclaringType() = c and
not v.isStatic()
|
v.hasSpecifier("private") or
v.hasSpecifier("protected")
) and
not exists(c.getABaseClass()) and
not exists(VirtualFunction f | f.getDeclaringType() = c)
}
/**
* Holds if `t` is an aggregate type, according to the rules specified in
* C++03 8.5.1(1):
*
* An aggregate is an array or a class (clause 9) with no user-declared
* constructors (12.1), no private or protected non-static data members
* (clause 11), no base classes (clause 10), and no virtual functions
* (10.3).
*/
predicate isAggregateType03(Type t) {
exists(Type ut | ut = t.getUnderlyingType() |
ut instanceof ArrayType or
isAggregateClass03(ut)
)
}
/**
* Holds if `c` is a POD class, according to the rules specified in
* C++03 9(4):
*
* A POD-struct is an aggregate class that has no non-static data members
* of type non-POD-struct, non-POD-union (or array of such types) or
* reference, and has no user-defined copy assignment operator and no
* user-defined destructor. Similarly, a POD-union is an aggregate union
* that has no non-static data members of type non-POD-struct,
* non-POD-union (or array of such types) or reference, and has no
* user-defined copy assignment operator and no user-defined destructor.
* A POD class is a class that is either a POD-struct or a POD-union.
*/
predicate isPodClass03(Class c) {
isAggregateClass03(c) and
not exists(Variable v |
v.getDeclaringType() = c and
not v.isStatic()
|
not isPodType03(v.getType())
or
exists(ArrayType at |
at = v.getType() and
not isPodType03(at.getBaseType())
)
or
v.getType() instanceof ReferenceType
) and
not exists(CopyAssignmentOperator o |
o.getDeclaringType() = c and
not o.isCompilerGenerated()
) and
not exists(Destructor dest |
dest.getDeclaringType() = c and
not dest.isCompilerGenerated()
)
}
/** DEPRECATED: Alias for isPodClass03 */
deprecated predicate isPODClass03 = isPodClass03/1;
/**
* Holds if `t` is a POD type, according to the rules specified in
* C++03 3.9(10):
*
* Scalar types, POD-struct types, POD-union types (clause 9), arrays of
* such types and cv-qualified versions of these types (3.9.3) are
* collectively called POD types.
*/
predicate isPodType03(Type t) {
exists(Type ut | ut = t.getUnderlyingType() |
isScalarType03(ut)
or
isPodClass03(ut)
or
exists(ArrayType at | at = ut and isPodType03(at.getBaseType()))
or
isPodType03(ut.(SpecifiedType).getUnspecifiedType())
)
}
/** DEPRECATED: Alias for isPodType03 */
deprecated predicate isPODType03 = isPodType03/1;