Skip to content

Commit 0e54709

Browse files
authored
Merge pull request #1859 from geoffw0/qldocpartialdef
CPP: Document PartialDefinitions
2 parents 641232a + 84da3e3 commit 0e54709

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ cached class FlowVar extends TFlowVar {
8484
*
8585
* In contrast to a normal "definition", which provides a new value for
8686
* something, a partial definition is an expression that may affect a
87-
* value, but does not necessarily replace it entirely. For example,
88-
* `x.y = 1;` is a partial definition of the object `x`.
87+
* value, but does not necessarily replace it entirely. For example:
88+
* ```
89+
* x.y = 1; // a partial definition of the object `x`.
90+
* x.y.z = 1; // a partial definition of the objects `x` and `x.y`.
91+
* x.setY(1); // a partial definition of the object `x`.
92+
* setY(&x); // a partial definition of the object `x`.
93+
* ```
8994
*/
9095
private module PartialDefinitions {
9196
private newtype TPartialDefinition =
@@ -121,8 +126,19 @@ private module PartialDefinitions {
121126

122127
predicate partiallyDefinesThis(ThisExpr e) { definedExpr = e }
123128

129+
/**
130+
* Gets the subBasicBlock where this `PartialDefinition` is defined.
131+
*/
124132
ControlFlowNode getSubBasicBlockStart() { result = node }
125133

134+
/**
135+
* Gets the expression that is being partially defined. For example in the
136+
* following code:
137+
* ```
138+
* x.y = 1;
139+
* ```
140+
* The expression `x` is being partially defined.
141+
*/
126142
Expr getDefinedExpr() { result = definedExpr }
127143

128144
Location getLocation() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
struct MyStruct
3+
{
4+
int x;
5+
struct MySubStruct {
6+
int z;
7+
} y;
8+
};
9+
10+
void test()
11+
{
12+
MyStruct s;
13+
14+
s.x = 1;
15+
s.y.z = 1;
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| partialdefinitions.cpp:14:2:14:2 | partial def of s | partialdefinitions.cpp:14:2:14:2 | s | partialdefinitions.cpp:14:2:14:8 | ... = ... |
2+
| partialdefinitions.cpp:15:2:15:2 | partial def of s | partialdefinitions.cpp:15:2:15:2 | s | partialdefinitions.cpp:15:2:15:10 | ... = ... |
3+
| partialdefinitions.cpp:15:4:15:4 | partial def of y | partialdefinitions.cpp:15:4:15:4 | y | partialdefinitions.cpp:15:2:15:10 | ... = ... |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import semmle.code.cpp.dataflow.internal.FlowVar
2+
3+
from PartialDefinition def
4+
select def, def.getDefinedExpr(), def.getSubBasicBlockStart()

0 commit comments

Comments
 (0)