Skip to content

Commit 271a759

Browse files
committed
C++: Move 'TIRDataFlowNode'.
1 parent b9595d9 commit 271a759

2 files changed

Lines changed: 77 additions & 52 deletions

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,83 @@ private import cpp
22

33
cached
44
private module Cached {
5-
5+
cached
6+
newtype TContent =
7+
TNonUnionContent(CanonicalField f, int indirectionIndex) {
8+
// the indirection index for field content starts at 1 (because `TNonUnionContent` is thought of as
9+
// the address of the field, `FieldAddress` in the IR).
10+
indirectionIndex = [1 .. max(SsaImpl::getMaxIndirectionsForType(f.getAnUnspecifiedType()))] and
11+
// Reads and writes of union fields are tracked using `UnionContent`.
12+
not f.getDeclaringType() instanceof Union
13+
} or
14+
TUnionContent(CanonicalUnion u, int bytes, int indirectionIndex) {
15+
exists(CanonicalField f |
16+
f = u.getACanonicalField() and
17+
bytes = getFieldSize(f) and
18+
// We key `UnionContent` by the union instead of its fields since a write to one
19+
// field can be read by any read of the union's fields. Again, the indirection index
20+
// is 1-based (because 0 is considered the address).
21+
indirectionIndex =
22+
[1 .. max(SsaImpl::getMaxIndirectionsForType(getAFieldWithSize(u, bytes)
23+
.getAnUnspecifiedType())
24+
)]
25+
)
26+
} or
27+
TElementContent(int indirectionIndex) {
28+
indirectionIndex = [1 .. getMaxElementContentIndirectionIndex()]
29+
}
30+
31+
/**
32+
* The IR dataflow graph consists of the following nodes:
33+
* - `Node0`, which injects most instructions and operands directly into the
34+
* dataflow graph.
35+
* - `VariableNode`, which is used to model flow through global variables.
36+
* - `PostUpdateNodeImpl`, which is used to model the state of an object after
37+
* an update after a number of loads.
38+
* - `SsaSynthNode`, which represents synthesized nodes as computed by the shared SSA
39+
* library.
40+
* - `RawIndirectOperand`, which represents the value of `operand` after
41+
* loading the address a number of times.
42+
* - `RawIndirectInstruction`, which represents the value of `instr` after
43+
* loading the address a number of times.
44+
*/
45+
cached
46+
newtype TIRDataFlowNode =
47+
TNode0(Node0Impl node) { DataFlowImplCommon::forceCachingInSameStage() } or
48+
TGlobalLikeVariableNode(GlobalLikeVariable var, int indirectionIndex) {
49+
indirectionIndex =
50+
[getMinIndirectionsForType(var.getUnspecifiedType()) .. SsaImpl::getMaxIndirectionsForType(var.getUnspecifiedType())]
51+
} or
52+
TPostUpdateNodeImpl(Operand operand, int indirectionIndex) {
53+
isPostUpdateNodeImpl(operand, indirectionIndex)
54+
} or
55+
TSsaSynthNode(SsaImpl::SynthNode n) or
56+
TSsaIteratorNode(IteratorFlow::IteratorFlowNode n) or
57+
TRawIndirectOperand0(Node0Impl node, int indirectionIndex) {
58+
SsaImpl::hasRawIndirectOperand(node.asOperand(), indirectionIndex)
59+
} or
60+
TRawIndirectInstruction0(Node0Impl node, int indirectionIndex) {
61+
not exists(node.asOperand()) and
62+
SsaImpl::hasRawIndirectInstruction(node.asInstruction(), indirectionIndex)
63+
} or
64+
TFinalParameterNode(Parameter p, int indirectionIndex) {
65+
exists(SsaImpl::FinalParameterUse use |
66+
use.getParameter() = p and
67+
use.getIndirectionIndex() = indirectionIndex
68+
)
69+
} or
70+
TFinalGlobalValue(SsaImpl::GlobalUse globalUse) or
71+
TInitialGlobalValue(SsaImpl::GlobalDef globalUse) or
72+
TBodyLessParameterNodeImpl(Parameter p, int indirectionIndex) {
73+
// Rule out parameters of catch blocks.
74+
not exists(p.getCatchBlock()) and
75+
// We subtract one because `getMaxIndirectionsForType` returns the maximum
76+
// indirection for a glvalue of a given type, and this doesn't apply to
77+
// parameters.
78+
indirectionIndex = [0 .. SsaImpl::getMaxIndirectionsForType(p.getUnspecifiedType()) - 1] and
79+
not any(InitializeParameterInstruction init).getParameter() = p
80+
} or
81+
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
682
}
783

884
import Cached

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

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,6 @@ private import Node0ToString
2020
private import DataFlowDispatch as DataFlowDispatch
2121
import ExprNodes
2222

23-
/**
24-
* The IR dataflow graph consists of the following nodes:
25-
* - `Node0`, which injects most instructions and operands directly into the
26-
* dataflow graph.
27-
* - `VariableNode`, which is used to model flow through global variables.
28-
* - `PostUpdateNodeImpl`, which is used to model the state of an object after
29-
* an update after a number of loads.
30-
* - `SsaSynthNode`, which represents synthesized nodes as computed by the shared SSA
31-
* library.
32-
* - `RawIndirectOperand`, which represents the value of `operand` after
33-
* loading the address a number of times.
34-
* - `RawIndirectInstruction`, which represents the value of `instr` after
35-
* loading the address a number of times.
36-
*/
37-
cached
38-
private newtype TIRDataFlowNode =
39-
TNode0(Node0Impl node) { DataFlowImplCommon::forceCachingInSameStage() } or
40-
TGlobalLikeVariableNode(GlobalLikeVariable var, int indirectionIndex) {
41-
indirectionIndex =
42-
[getMinIndirectionsForType(var.getUnspecifiedType()) .. SsaImpl::getMaxIndirectionsForType(var.getUnspecifiedType())]
43-
} or
44-
TPostUpdateNodeImpl(Operand operand, int indirectionIndex) {
45-
isPostUpdateNodeImpl(operand, indirectionIndex)
46-
} or
47-
TSsaSynthNode(SsaImpl::SynthNode n) or
48-
TSsaIteratorNode(IteratorFlow::IteratorFlowNode n) or
49-
TRawIndirectOperand0(Node0Impl node, int indirectionIndex) {
50-
SsaImpl::hasRawIndirectOperand(node.asOperand(), indirectionIndex)
51-
} or
52-
TRawIndirectInstruction0(Node0Impl node, int indirectionIndex) {
53-
not exists(node.asOperand()) and
54-
SsaImpl::hasRawIndirectInstruction(node.asInstruction(), indirectionIndex)
55-
} or
56-
TFinalParameterNode(Parameter p, int indirectionIndex) {
57-
exists(SsaImpl::FinalParameterUse use |
58-
use.getParameter() = p and
59-
use.getIndirectionIndex() = indirectionIndex
60-
)
61-
} or
62-
TFinalGlobalValue(SsaImpl::GlobalUse globalUse) or
63-
TInitialGlobalValue(SsaImpl::GlobalDef globalUse) or
64-
TBodyLessParameterNodeImpl(Parameter p, int indirectionIndex) {
65-
// Rule out parameters of catch blocks.
66-
not exists(p.getCatchBlock()) and
67-
// We subtract one because `getMaxIndirectionsForType` returns the maximum
68-
// indirection for a glvalue of a given type, and this doesn't apply to
69-
// parameters.
70-
indirectionIndex = [0 .. SsaImpl::getMaxIndirectionsForType(p.getUnspecifiedType()) - 1] and
71-
not any(InitializeParameterInstruction init).getParameter() = p
72-
} or
73-
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
7423

7524
/**
7625
* An operand that is defined by a `FieldAddressInstruction`.

0 commit comments

Comments
 (0)