Skip to content

Commit 28aa7dc

Browse files
C++: Fix PR feedback
1 parent 21f6ab7 commit 28aa7dc

File tree

2 files changed

+165
-106
lines changed

2 files changed

+165
-106
lines changed

change-notes/1.23/analysis-cpp.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ The following changes in version 1.23 affect C/C++ analysis in all applications.
3535
* There is now a `DataFlow::localExprFlow` predicate and a
3636
`TaintTracking::localExprTaint` predicate to make it easy to use the most
3737
common case of local data flow and taint: from one `Expr` to another.
38+
* The member predicates of the `FunctionInput` and `FunctionOutput` classes have been renamed for
39+
clarity (e.g. `isOutReturnPointer()` to `isReturnValueDeref()`). The existing member predicates
40+
have been deprecated, and will be removed in a future release. Code that uses the old member
41+
predicates should be updated to use the corresponding new member predicate.

cpp/ql/src/semmle/code/cpp/models/interfaces/FunctionInputsAndOutputs.qll

Lines changed: 161 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,87 @@ private newtype TFunctionInput =
2929
class FunctionInput extends TFunctionInput {
3030
abstract string toString();
3131

32+
/**
33+
* Holds if this is the input value of the parameter with index `index`.
34+
* Example:
35+
* ```
36+
* void func(int n, char* p, float& r);
37+
* ```
38+
* `isParameter(0)` holds for the `FunctionInput` that represents the value of `n` (with type
39+
* `int`) on entry to the function.
40+
* `isParameter(1)` holds for the `FunctionInput` that represents the value of `p` (with type
41+
* `char*`) on entry to the function.
42+
* `isParameter(2)` holds for the `FunctionInput` that represents the "value" of the reference `r`
43+
* (with type `float&`) on entry to the function, _not_ the value of the referred-to `float`.
44+
*/
3245
predicate isParameter(ParameterIndex index) { none() }
3346

47+
/**
48+
* Holds if this is the input value of the parameter with index `index`.
49+
* DEPRECATED: Use `isParameter(index)` instead.
50+
*/
51+
deprecated final predicate isInParameter(ParameterIndex index) { isParameter(index) }
52+
53+
/**
54+
* Holds if this is the input value pointed to by a pointer parameter to a function, or the input
55+
* value referred to by a reference parameter to a function, where the parameter has index
56+
* `index`.
57+
* Example:
58+
* ```
59+
* void func(int n, char* p, float& r);
60+
* ```
61+
* `isParameterDeref(1)` holds for the `FunctionInput` that represents the value of `*p` (with
62+
* type `char`) on entry to the function.
63+
* `isParameterDeref(2)` holds for the `FunctionInput` that represents the value of `r` (with type
64+
* `float`) on entry to the function.
65+
* There is no `FunctionInput` for which `isParameterDeref(0)` holds, because `n` is neither a
66+
* pointer nor a reference.
67+
*/
3468
predicate isParameterDeref(ParameterIndex index) { none() }
3569

70+
/**
71+
* Holds if this is the input value pointed to by a pointer parameter to a function, or the input
72+
* value referred to by a reference parameter to a function, where the parameter has index
73+
* `index`.
74+
* DEPRECATED: Use `isParameterDeref(index)` instead.
75+
*/
76+
deprecated final predicate isInParameterPointer(ParameterIndex index) { isParameterDeref(index) }
77+
78+
/**
79+
* Holds if this is the input value pointed to by the `this` pointer of an instance member
80+
* function.
81+
* Example:
82+
* ```
83+
* struct C {
84+
* void mfunc(int n, char* p, float& r) const;
85+
* };
86+
* ```
87+
* `isQualifierObject()` holds for the `FunctionInput` that represents the value of `*this` (with
88+
* type `C const`) on entry to the function.
89+
*/
3690
predicate isQualifierObject() { none() }
3791

92+
/**
93+
* Holds if this is the input value pointed to by the `this` pointer of an instance member
94+
* function.
95+
* DEPRECATED: Use `isQualifierObject()` instead.
96+
*/
97+
deprecated final predicate isInQualifier() { isQualifierObject() }
98+
99+
/**
100+
* Holds if this is the input value of the `this` pointer of an instance member function.
101+
* Example:
102+
* ```
103+
* struct C {
104+
* void mfunc(int n, char* p, float& r) const;
105+
* };
106+
* ```
107+
* `isQualifierAddress()` holds for the `FunctionInput` that represents the value of `this` (with
108+
* type `C const *`) on entry to the function.
109+
*/
38110
predicate isQualifierAddress() { none() }
39111
}
40112

41-
/**
42-
* The input value of a parameter to a function.
43-
* Example:
44-
* ```cpp
45-
* void func(int n, char* p, float& r);
46-
* ```
47-
* The `InParameter` with `getIndex() = 0` represents the value of `n` (with type `int`) on entry to
48-
* the function.
49-
* The `InParameter` with `getIndex() = 1` represents the value of `p` (with type `char*`) on entry
50-
* to the function.
51-
* The `InParameter` with `getIndex() = 2` represents the "value" of the reference `r` (with type
52-
* `float&`) on entry to the function, _not_ the value of the referred-to `float`.
53-
*/
54113
class InParameter extends FunctionInput, TInParameter {
55114
ParameterIndex index;
56115

@@ -64,20 +123,6 @@ class InParameter extends FunctionInput, TInParameter {
64123
override predicate isParameter(ParameterIndex i) { i = index }
65124
}
66125

67-
/**
68-
* The input value pointed to by a pointer parameter to a function, or the input value referred to
69-
* by a reference parameter to a function.
70-
* Example:
71-
* ```cpp
72-
* void func(int n, char* p, float& r);
73-
* ```
74-
* The `InParameterDeref` with `getIndex() = 1` represents the value of `*p` (with type `char`) on
75-
* entry to the function.
76-
* The `InParameterDeref` with `getIndex() = 2` represents the value of `r` (with type `float`) on
77-
* entry to the function.
78-
* There is no `InParameterDeref` with `getIndex() = 0`, because `n` is neither a pointer nor a
79-
* reference.
80-
*/
81126
class InParameterDeref extends FunctionInput, TInParameterDeref {
82127
ParameterIndex index;
83128

@@ -91,34 +136,12 @@ class InParameterDeref extends FunctionInput, TInParameterDeref {
91136
override predicate isParameterDeref(ParameterIndex i) { i = index }
92137
}
93138

94-
/**
95-
* The input value pointed to by the `this` pointer of an instance member function.
96-
* Example:
97-
* ```cpp
98-
* struct C {
99-
* void mfunc(int n, char* p, float& r) const;
100-
* };
101-
* ```
102-
* The `InQualifierObject` represents the value of `*this` (with type `C const`) on entry to the
103-
* function.
104-
*/
105139
class InQualifierObject extends FunctionInput, TInQualifierObject {
106140
override string toString() { result = "InQualifierObject" }
107141

108142
override predicate isQualifierObject() { any() }
109143
}
110144

111-
/**
112-
* The input value of the `this` pointer of an instance member function.
113-
* Example:
114-
* ```cpp
115-
* struct C {
116-
* void mfunc(int n, char* p, float& r) const;
117-
* };
118-
* ```
119-
* The `InQualifierAddress` represents the value of `this` (with type `C const *`) on entry to the
120-
* function.
121-
*/
122145
class InQualifierAddress extends FunctionInput, TInQualifierAddress {
123146
override string toString() { result = "InQualifierAddress" }
124147

@@ -142,29 +165,104 @@ private newtype TFunctionOutput =
142165
class FunctionOutput extends TFunctionOutput {
143166
abstract string toString();
144167

168+
/**
169+
* Holds if this is the output value pointed to by a pointer parameter to a function, or the
170+
* output value referred to by a reference parameter to a function, where the parameter has
171+
* index `index`.
172+
* Example:
173+
* ```
174+
* void func(int n, char* p, float& r);
175+
* ```
176+
* `isParameterDeref(1)` holds for the `FunctionOutput` that represents the value of `*p` (with
177+
* type `char`) on return from the function.
178+
* `isParameterDeref(2)` holds for the `FunctionOutput` that represents the value of `r` (with
179+
* type `float`) on return from the function.
180+
* There is no `FunctionOutput` for which `isParameterDeref(0)` holds, because `n` is neither a
181+
* pointer nor a reference.
182+
*/
145183
predicate isParameterDeref(ParameterIndex i) { none() }
146184

185+
/**
186+
* Holds if this is the output value pointed to by a pointer parameter to a function, or the
187+
* output value referred to by a reference parameter to a function, where the parameter has
188+
* index `index`.
189+
* DEPRECATED: Use `isParameterDeref(index)` instead.
190+
*/
191+
deprecated final predicate isOutParameterPointer(ParameterIndex index) { isParameterDeref(index) }
192+
193+
/**
194+
* Holds if this is the output value pointed to by the `this` pointer of an instance member
195+
* function.
196+
* ```
197+
* struct C {
198+
* void mfunc(int n, char* p, float& r);
199+
* };
200+
* ```
201+
* `isQualifierObject()` holds for the `FunctionOutput` that represents the value of `*this` (with
202+
* type `C`) on return from the function.
203+
*/
147204
predicate isQualifierObject() { none() }
148205

206+
/**
207+
* Holds if this is the output value pointed to by the `this` pointer of an instance member
208+
* function.
209+
* DEPRECATED: Use `isQualifierObject()` instead.
210+
*/
211+
deprecated final predicate isOutQualifier() { isQualifierObject() }
212+
213+
/**
214+
* Holds if this is the value returned by a function.
215+
* Example:
216+
* ```
217+
* int getInt();
218+
* char* getPointer();
219+
* float& getReference();
220+
* ```
221+
* `isReturnValue()` holds for the `FunctionOutput` that represents the value returned by
222+
* `getInt()` (with type `int`).
223+
* `isReturnValue()` holds for the `FunctionOutput` that represents the value returned by
224+
* `getPointer()` (with type `char*`).
225+
* `isReturnValue()` holds for the `FunctionOutput` that represents the "value" of the reference
226+
* returned by `getReference()` (with type `float&`), _not_ the value of the referred-to
227+
* `float`.
228+
*/
149229
predicate isReturnValue() { none() }
150230

231+
/**
232+
* Holds if this is the value returned by a function.
233+
* DEPRECATED: Use `isReturnValue()` instead.
234+
*/
235+
deprecated final predicate isOutReturnValue() { isReturnValue() }
236+
237+
/**
238+
* Holds if this is the output value pointed to by the return value of a function, if the function
239+
* returns a pointer, or the output value referred to by the return value of a function, if the
240+
* function returns a reference.
241+
* Example:
242+
* ```
243+
* char* getPointer();
244+
* float& getReference();
245+
* int getInt();
246+
* ```
247+
* `isReturnValueDeref()` holds for the `FunctionOutput` that represents the value of
248+
* `*getPointer()` (with type `char`).
249+
* `isReturnValueDeref()` holds for the `FunctionOutput` that represents the value of
250+
* `getReference()` (with type `float`).
251+
* There is no `FunctionOutput` of `getInt()` for which `isReturnValueDeref()` holds because the
252+
* return type of `getInt()` is neither a pointer nor a reference.
253+
*/
151254
predicate isReturnValueDeref() { none() }
255+
256+
/*
257+
* Holds if this is the output value pointed to by the return value of a function, if the function
258+
* returns a pointer, or the output value referred to by the return value of a function, if the
259+
* function returns a reference.
260+
* DEPRECATED: Use `isReturnValueDeref()` instead.
261+
*/
262+
263+
deprecated final predicate isOutReturnPointer() { isReturnValueDeref() }
152264
}
153265

154-
/**
155-
* The output value pointed to by a pointer parameter to a function, or the output value referred to
156-
* by a reference parameter to a function.
157-
* Example:
158-
* ```cpp
159-
* void func(int n, char* p, float& r);
160-
* ```
161-
* The `OutParameterDeref` with `getIndex() = 1` represents the value of `*p` (with type `char`) on
162-
* return from the function.
163-
* The `OutParameterDeref` with `getIndex() = 2` represents the value of `r` (with type `float`) on
164-
* return from the function.
165-
* There is no `OutParameterDeref` with `getIndex() = 0`, because `n` is neither a pointer nor a
166-
* reference.
167-
*/
168266
class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
169267
ParameterIndex index;
170268

@@ -177,61 +275,18 @@ class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
177275
override predicate isParameterDeref(ParameterIndex i) { i = index }
178276
}
179277

180-
/**
181-
* The output value pointed to by the `this` pointer of an instance member function.
182-
* Example:
183-
* ```cpp
184-
* struct C {
185-
* void mfunc(int n, char* p, float& r);
186-
* };
187-
* ```
188-
* The `OutQualifierObject` represents the value of `*this` (with type `C`) on return from the
189-
* function.
190-
*/
191278
class OutQualifierObject extends FunctionOutput, TOutQualifierObject {
192279
override string toString() { result = "OutQualifier" }
193280

194281
override predicate isQualifierObject() { any() }
195282
}
196283

197-
/**
198-
* The value returned by a function.
199-
* Example:
200-
* ```cpp
201-
* int getInt();
202-
* char* getPointer();
203-
* float& getReference();
204-
* ```
205-
* The `OutReturnValue` for `getInt()` represents the value returned by `getInt()` (with type
206-
* `int`).
207-
* The `OutReturnValue` for `getPointer()` represents the value returned by `getPointer()` (with
208-
* type `char*`).
209-
* The `OutReturnValue` for `getReference()` represents the "value" of the reference returned by
210-
* `getReference()` (with type `float&`), _not_ the value of the referred-to `float`.
211-
*/
212284
class OutReturnValue extends FunctionOutput, TOutReturnValue {
213285
override string toString() { result = "OutReturnValue" }
214286

215287
override predicate isReturnValue() { any() }
216288
}
217289

218-
/**
219-
* The output value pointed to by the return value of a function, if the function returns a pointer,
220-
* or the output value referred to by the return value of a function, if the function returns a
221-
* reference.
222-
* Example:
223-
* ```cpp
224-
* char* getPointer();
225-
* float& getReference();
226-
* int getInt();
227-
* ```
228-
* The `OutReturnValueDeref` for `getPointer()` represents the value of `*getPointer()` (with type
229-
* `char`).
230-
* The `OutReturnValueDeref` for `getReference()` represents the value of `getReference()` (with
231-
* type `float`).
232-
* There is no `OutReturnValueDeref` for `getInt()`, because the return type of `getInt()` is
233-
* neither a pointer nor a reference.
234-
*/
235290
class OutReturnValueDeref extends FunctionOutput, TOutReturnValueDeref {
236291
override string toString() { result = "OutReturnValueDeref" }
237292

0 commit comments

Comments
 (0)