Skip to content

Commit afcc6ac

Browse files
authored
Merge pull request github#3766 from rdmarsh2/rdmarsh/cpp/add-qldoc-3
C++: Add QLDocs for Initializer.qll-Macro.qll and model classes
2 parents 30d9c6b + edaa43a commit afcc6ac

File tree

10 files changed

+166
-4
lines changed

10 files changed

+166
-4
lines changed

cpp/ql/src/semmle/code/cpp/Initializer.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides the `Initializer` class, representing C/C++ declaration initializers.
3+
*/
4+
15
import semmle.code.cpp.controlflow.ControlFlowGraph
26

37
/**

cpp/ql/src/semmle/code/cpp/Iteration.qll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes for loop iteration variables.
3+
*/
4+
15
import semmle.code.cpp.Variable
26

37
/**
@@ -7,14 +11,18 @@ import semmle.code.cpp.Variable
711
class LoopCounter extends Variable {
812
LoopCounter() { exists(ForStmt f | f.getAnIterationVariable() = this) }
913

10-
// Gets an access of this variable within loop `f`.
14+
/**
15+
* Gets an access of this variable within loop `f`.
16+
*/
1117
VariableAccess getVariableAccessInLoop(ForStmt f) {
1218
this.getALoop() = f and
1319
result.getEnclosingStmt().getParent*() = f and
1420
this = result.getTarget()
1521
}
1622

17-
// Gets a loop which uses this variable as its counter.
23+
/**
24+
* Gets a loop which uses this variable as its counter.
25+
*/
1826
ForStmt getALoop() { result.getAnIterationVariable() = this }
1927
}
2028

@@ -25,14 +33,18 @@ class LoopCounter extends Variable {
2533
class LoopControlVariable extends Variable {
2634
LoopControlVariable() { this = loopControlVariable(_) }
2735

28-
// Gets an access of this variable within loop `f`.
36+
/**
37+
* Gets an access of this variable within loop `f`.
38+
*/
2939
VariableAccess getVariableAccessInLoop(ForStmt f) {
3040
this.getALoop() = f and
3141
result.getEnclosingStmt().getParent*() = f and
3242
this = result.getTarget()
3343
}
3444

35-
// Gets a loop which uses this variable as its control variable.
45+
/**
46+
* Gets a loop which uses this variable as its control variable.
47+
*/
3648
ForStmt getALoop() { this = loopControlVariable(result) }
3749
}
3850

cpp/ql/src/semmle/code/cpp/Linkage.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Proivdes the `LinkTarget` class representing linker invocations during the build process.
3+
*/
4+
15
import semmle.code.cpp.Class
26
import semmle.code.cpp.File
37
import semmle.code.cpp.Function

cpp/ql/src/semmle/code/cpp/Location.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for locations in the source code.
3+
*/
4+
15
import semmle.code.cpp.Element
26
import semmle.code.cpp.File
37

cpp/ql/src/semmle/code/cpp/Macro.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ class MacroInvocation extends MacroAccess {
179179
result.(Stmt).getGeneratingMacro() = this
180180
}
181181

182+
/**
183+
* Gets a function that includes an expression that is affected by this macro
184+
* invocation. If the macro expansion includes the end of one function and
185+
* the beginning of another, this predicate will get both.
186+
*/
182187
Function getEnclosingFunction() {
183188
result = this.getAnAffectedElement().(Expr).getEnclosingFunction()
184189
}

cpp/ql/src/semmle/code/cpp/models/implementations/Printf.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* Provides implementation classes modelling various standard formatting
3+
* functions (`printf`, `snprintf` etc).
4+
* See `semmle.code.cpp.models.interfaces.FormattingFunction` for usage
5+
* information.
6+
*/
7+
18
import semmle.code.cpp.models.interfaces.FormattingFunction
29
import semmle.code.cpp.models.interfaces.Alias
310

cpp/ql/src/semmle/code/cpp/models/implementations/Strcat.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provides implementation classes modelling `strcat` and various similar functions.
3+
* See `semmle.code.cpp.models.Models` for usage information.
4+
*/
5+
16
import semmle.code.cpp.models.interfaces.ArrayFunction
27
import semmle.code.cpp.models.interfaces.DataFlow
38
import semmle.code.cpp.models.interfaces.Taint

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,10 @@ import semmle.code.cpp.models.Models
1919
* to destinations; that is covered by `TaintModel.qll`.
2020
*/
2121
abstract class DataFlowFunction extends Function {
22+
/**
23+
* Holds if data can be copied from the argument, qualifier, or buffer
24+
* represented by `input` to the return value or buffer represented by
25+
* `output`
26+
*/
2227
abstract predicate hasDataFlow(FunctionInput input, FunctionOutput output);
2328
}

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ class FunctionInput extends TFunctionInput {
108108
predicate isQualifierAddress() { none() }
109109
}
110110

111+
/**
112+
* The input value of a parameter.
113+
*
114+
* Example:
115+
* ```
116+
* void func(int n, char* p, float& r);
117+
* ```
118+
* - There is an `InParameter` representing the value of `n` (with type `int`) on entry to the
119+
* function.
120+
* - There is an `InParameter` representing the value of `p` (with type `char*`) on entry to the
121+
* function.
122+
* - There is an `InParameter` representing the "value" of the reference `r` (with type `float&`) on
123+
* entry to the function, _not_ the value of the referred-to `float`.
124+
*/
111125
class InParameter extends FunctionInput, TInParameter {
112126
ParameterIndex index;
113127

@@ -121,6 +135,21 @@ class InParameter extends FunctionInput, TInParameter {
121135
override predicate isParameter(ParameterIndex i) { i = index }
122136
}
123137

138+
/**
139+
* The input value pointed to by a pointer parameter to a function, or the input value referred to
140+
* by a reference parameter to a function.
141+
*
142+
* Example:
143+
* ```
144+
* void func(int n, char* p, float& r);
145+
* ```
146+
* - There is an `InParameterDeref` with `getIndex() = 1` that represents the value of `*p` (with
147+
* type `char`) on entry to the function.
148+
* - There is an `InParameterDeref` with `getIndex() = 2` that represents the value of `r` (with
149+
* type `float`) on entry to the function.
150+
* - There is no `InParameterDeref` representing the value of `n`, because `n` is neither a pointer
151+
* nor a reference.
152+
*/
124153
class InParameterDeref extends FunctionInput, TInParameterDeref {
125154
ParameterIndex index;
126155

@@ -134,12 +163,36 @@ class InParameterDeref extends FunctionInput, TInParameterDeref {
134163
override predicate isParameterDeref(ParameterIndex i) { i = index }
135164
}
136165

166+
/**
167+
* The input value pointed to by the `this` pointer of an instance member function.
168+
*
169+
* Example:
170+
* ```
171+
* struct C {
172+
* void mfunc(int n, char* p, float& r) const;
173+
* };
174+
* ```
175+
* - `InQualifierObject` represents the value of `*this` (with type `C const`) on entry to the
176+
* function.
177+
*/
137178
class InQualifierObject extends FunctionInput, TInQualifierObject {
138179
override string toString() { result = "InQualifierObject" }
139180

140181
override predicate isQualifierObject() { any() }
141182
}
142183

184+
/**
185+
* The input value of the `this` pointer of an instance member function.
186+
*
187+
* Example:
188+
* ```
189+
* struct C {
190+
* void mfunc(int n, char* p, float& r) const;
191+
* };
192+
* ```
193+
* - `InQualifierAddress` represents the value of `this` (with type `C const *`) on entry to the
194+
* function.
195+
*/
143196
class InQualifierAddress extends FunctionInput, TInQualifierAddress {
144197
override string toString() { result = "InQualifierAddress" }
145198

@@ -265,6 +318,21 @@ class FunctionOutput extends TFunctionOutput {
265318
deprecated final predicate isOutReturnPointer() { isReturnValueDeref() }
266319
}
267320

321+
/**
322+
* The output value pointed to by a pointer parameter to a function, or the output value referred to
323+
* by a reference parameter to a function.
324+
*
325+
* Example:
326+
* ```
327+
* void func(int n, char* p, float& r);
328+
* ```
329+
* - There is an `OutParameterDeref` with `getIndex()=1` that represents the value of `*p` (with
330+
* type `char`) on return from the function.
331+
* - There is an `OutParameterDeref` with `getIndex()=2` that represents the value of `r` (with
332+
* type `float`) on return from the function.
333+
* - There is no `OutParameterDeref` representing the value of `n`, because `n` is neither a
334+
* pointer nor a reference.
335+
*/
268336
class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
269337
ParameterIndex index;
270338

@@ -277,18 +345,62 @@ class OutParameterDeref extends FunctionOutput, TOutParameterDeref {
277345
override predicate isParameterDeref(ParameterIndex i) { i = index }
278346
}
279347

348+
/**
349+
* The output value pointed to by the `this` pointer of an instance member function.
350+
*
351+
* Example:
352+
* ```
353+
* struct C {
354+
* void mfunc(int n, char* p, float& r);
355+
* };
356+
* ```
357+
* - The `OutQualifierObject` represents the value of `*this` (with type `C`) on return from the
358+
* function.
359+
*/
280360
class OutQualifierObject extends FunctionOutput, TOutQualifierObject {
281361
override string toString() { result = "OutQualifierObject" }
282362

283363
override predicate isQualifierObject() { any() }
284364
}
285365

366+
/**
367+
* The value returned by a function.
368+
*
369+
* Example:
370+
* ```
371+
* int getInt();
372+
* char* getPointer();
373+
* float& getReference();
374+
* ```
375+
* - `OutReturnValue` represents the value returned by
376+
* `getInt()` (with type `int`).
377+
* - `OutReturnValue` represents the value returned by
378+
* `getPointer()` (with type `char*`).
379+
* - `OutReturnValue` represents the "value" of the reference returned by `getReference()` (with
380+
* type `float&`), _not_ the value of the referred-to `float`.
381+
*/
286382
class OutReturnValue extends FunctionOutput, TOutReturnValue {
287383
override string toString() { result = "OutReturnValue" }
288384

289385
override predicate isReturnValue() { any() }
290386
}
291387

388+
/**
389+
* The output value pointed to by the return value of a function, if the function returns a pointer,
390+
* or the output value referred to by the return value of a function, if the function returns a
391+
* reference.
392+
*
393+
* Example:
394+
* ```
395+
* char* getPointer();
396+
* float& getReference();
397+
* int getInt();
398+
* ```
399+
* - `OutReturnValueDeref` represents the value of `*getPointer()` (with type `char`).
400+
* - `OutReturnValueDeref` represents the value of `getReference()` (with type `float`).
401+
* - `OutReturnValueDeref` does not represent the return value of `getInt()` because the return type
402+
* of `getInt()` is neither a pointer nor a reference.
403+
*/
292404
class OutReturnValueDeref extends FunctionOutput, TOutReturnValueDeref {
293405
override string toString() { result = "OutReturnValueDeref" }
294406

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@ import semmle.code.cpp.models.Models
2424
* data flow.
2525
*/
2626
abstract class TaintFunction extends Function {
27+
/**
28+
* Holds if data passed into the argument, qualifier, or buffer represented by
29+
* `input` influences the return value or buffer represented by `output`
30+
*/
2731
abstract predicate hasTaintFlow(FunctionInput input, FunctionOutput output);
2832
}

0 commit comments

Comments
 (0)