Skip to content

Commit 6c87b08

Browse files
committed
C++: Respond to review comments:
- ArgumentNode is now abstract - PrimaryArgumentNode is now an OperandNode. - ArgumentIndirectionNode is now merged into SideEffectArgumentNode.
1 parent 4c14f5d commit 6c87b08

File tree

3 files changed

+18
-53
lines changed

3 files changed

+18
-53
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,15 @@ private import DataFlowDispatch
55

66
/**
77
* A data flow node that occurs as the argument of a call and is passed as-is
8-
* to the callable. Instance arguments (`this` pointer) are also included.
8+
* to the callable. Instance arguments (`this` pointer) and read side effects
9+
* on parameters are also included.
910
*/
10-
class ArgumentNode extends Node {
11-
ArgumentNode() {
12-
// To avoid making this class abstract, we enumerate its values here.
13-
this instanceof PrimaryArgumentNode or
14-
this instanceof SideEffectArgumentNode
15-
}
16-
11+
abstract class ArgumentNode extends OperandNode {
1712
/**
1813
* Holds if this argument occurs at the given position in the given call.
1914
* The instance argument is considered to have index `-1`.
2015
*/
21-
predicate argumentOf(DataFlowCall call, int pos) {
22-
this.(PrimaryArgumentNode).argumentOf(call, pos) or
23-
this.(SideEffectArgumentNode).argumentOf(call, pos)
24-
}
16+
abstract predicate argumentOf(DataFlowCall call, int pos);
2517

2618
/** Gets the call in which this node is an argument. */
2719
DataFlowCall getCall() { this.argumentOf(result, _) }
@@ -31,44 +23,34 @@ class ArgumentNode extends Node {
3123
* A data flow node that occurs as the argument to a call, or an
3224
* implicit `this` pointer argument.
3325
*/
34-
private class PrimaryArgumentNode extends InstructionNode {
35-
PrimaryArgumentNode() { exists(CallInstruction call | instr = call.getAnArgument()) }
26+
private class PrimaryArgumentNode extends ArgumentNode {
27+
override ArgumentOperand op;
3628

37-
/**
38-
* Holds if this argument occurs at the given position in the given call.
39-
* The instance argument is considered to have index `-1`.
40-
*/
41-
predicate argumentOf(DataFlowCall call, int pos) {
42-
instr = call.getPositionalArgument(pos)
29+
PrimaryArgumentNode() { exists(CallInstruction call | op = call.getAnArgumentOperand()) }
30+
31+
override predicate argumentOf(DataFlowCall call, int pos) {
32+
op = call.getPositionalArgumentOperand(pos)
4333
or
44-
instr = call.getThisArgument() and pos = -1
34+
op = call.getThisArgumentOperand() and pos = -1
4535
}
4636
}
4737

4838
/**
4939
* A data flow node representing the read side effect of a call on a
5040
* specific parameter.
5141
*/
52-
private class SideEffectArgumentNode extends OperandNode {
42+
private class SideEffectArgumentNode extends ArgumentNode {
5343
override SideEffectOperand op;
5444
ReadSideEffectInstruction read;
5545

56-
SideEffectArgumentNode() {
57-
exists(CallInstruction call |
58-
read.getPrimaryInstruction() = call and
59-
op = read.getSideEffectOperand()
60-
)
61-
}
46+
SideEffectArgumentNode() { op = read.getSideEffectOperand() }
6247

63-
/**
64-
* Holds if this argument occurs at the given position in the given call.
65-
* See `getArgumentPosOfSideEffect` for a describing of how read side effects
66-
* are assigned an argument position.
67-
*/
68-
predicate argumentOf(DataFlowCall call, int pos) {
48+
override predicate argumentOf(DataFlowCall call, int pos) {
6949
read.getPrimaryInstruction() = call and
7050
pos = getArgumentPosOfSideEffect(read.getIndex())
7151
}
52+
53+
override string toString() { result = "Argument " + read.getIndex() + " indirection" }
7254
}
7355

7456
private newtype TReturnKind =

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -505,21 +505,6 @@ class DefinitionByReferenceNode extends InstructionNode {
505505
}
506506
}
507507

508-
/**
509-
* A node representing the memory pointed to by a function argument.
510-
*
511-
* This class exists only in order to override `toString`, which would
512-
* otherwise be the default implementation inherited from `OperandNode`.
513-
*/
514-
private class ArgumentIndirectionNode extends OperandNode {
515-
override SideEffectOperand op;
516-
ReadSideEffectInstruction read;
517-
518-
ArgumentIndirectionNode() { read.getSideEffectOperand() = op }
519-
520-
override string toString() { result = "Argument " + read.getIndex() + " indirection" }
521-
}
522-
523508
/**
524509
* A `Node` corresponding to a variable in the program, as opposed to the
525510
* value of that variable at some particular point. This can be used for

cpp/ql/test/library-tests/dataflow/fields/ir-path-flow.expected

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
edges
22
| A.cpp:55:5:55:5 | set output argument [c] | A.cpp:56:13:56:15 | call to get |
33
| A.cpp:55:12:55:19 | (C *)... | A.cpp:55:5:55:5 | set output argument [c] |
4-
| A.cpp:55:12:55:19 | new | A.cpp:55:12:55:19 | (C *)... |
4+
| A.cpp:55:12:55:19 | new | A.cpp:55:5:55:5 | set output argument [c] |
55
| A.cpp:57:11:57:24 | B output argument [c] | A.cpp:57:28:57:30 | call to get |
66
| A.cpp:57:17:57:23 | new | A.cpp:57:11:57:24 | B output argument [c] |
77
| A.cpp:98:12:98:18 | new | A.cpp:100:5:100:13 | Store |
@@ -19,12 +19,11 @@ edges
1919
| A.cpp:143:7:143:31 | Chi [b] | A.cpp:151:12:151:24 | D output argument [b] |
2020
| A.cpp:143:7:143:31 | Store | A.cpp:143:7:143:31 | Chi [b] |
2121
| A.cpp:143:25:143:31 | new | A.cpp:143:7:143:31 | Store |
22-
| A.cpp:150:12:150:18 | new | A.cpp:151:18:151:18 | b |
22+
| A.cpp:150:12:150:18 | new | A.cpp:151:12:151:24 | D output argument [b] |
2323
| A.cpp:151:12:151:24 | Chi [b] | A.cpp:152:13:152:13 | b |
2424
| A.cpp:151:12:151:24 | D output argument [b] | A.cpp:151:12:151:24 | Chi [b] |
2525
| A.cpp:151:18:151:18 | Chi [c] | A.cpp:154:13:154:13 | c |
2626
| A.cpp:151:18:151:18 | D output argument [c] | A.cpp:151:18:151:18 | Chi [c] |
27-
| A.cpp:151:18:151:18 | b | A.cpp:151:12:151:24 | D output argument [b] |
2827
| C.cpp:18:12:18:18 | C output argument [s1] | C.cpp:27:8:27:11 | *#this [s1] |
2928
| C.cpp:18:12:18:18 | C output argument [s3] | C.cpp:27:8:27:11 | *#this [s3] |
3029
| C.cpp:22:12:22:21 | Chi [s1] | C.cpp:24:5:24:25 | Chi [s1] |
@@ -229,7 +228,6 @@ nodes
229228
| A.cpp:151:12:151:24 | D output argument [b] | semmle.label | D output argument [b] |
230229
| A.cpp:151:18:151:18 | Chi [c] | semmle.label | Chi [c] |
231230
| A.cpp:151:18:151:18 | D output argument [c] | semmle.label | D output argument [c] |
232-
| A.cpp:151:18:151:18 | b | semmle.label | b |
233231
| A.cpp:152:13:152:13 | b | semmle.label | b |
234232
| A.cpp:154:13:154:13 | c | semmle.label | c |
235233
| C.cpp:18:12:18:18 | C output argument [s1] | semmle.label | C output argument [s1] |

0 commit comments

Comments
 (0)