Skip to content

Commit 7d05759

Browse files
authored
Merge pull request github#3857 from jbj/flowthrough-bigstep-perf
C++: Remove big-step relation in flow-through code
2 parents 50cd759 + cff0f48 commit 7d05759

File tree

4 files changed

+40
-204
lines changed

4 files changed

+40
-204
lines changed

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

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -147,54 +147,6 @@ private module Cached {
147147
}
148148
}
149149

150-
private module LocalFlowBigStep {
151-
private predicate localFlowEntry(Node n) {
152-
Cand::cand(_, n) and
153-
(
154-
n instanceof ParameterNode or
155-
n instanceof OutNode or
156-
readStep(_, _, n) or
157-
n instanceof CastNode
158-
)
159-
}
160-
161-
private predicate localFlowExit(Node n) {
162-
Cand::cand(_, n) and
163-
(
164-
n instanceof ArgumentNode
165-
or
166-
n instanceof ReturnNode
167-
or
168-
readStep(n, _, _)
169-
or
170-
n instanceof CastNode
171-
or
172-
n =
173-
any(PostUpdateNode pun | Cand::parameterValueFlowsToPreUpdateCand(_, pun))
174-
.getPreUpdateNode()
175-
)
176-
}
177-
178-
pragma[nomagic]
179-
private predicate localFlowStepPlus(Node node1, Node node2) {
180-
localFlowEntry(node1) and
181-
simpleLocalFlowStep(node1, node2) and
182-
node1 != node2
183-
or
184-
exists(Node mid |
185-
localFlowStepPlus(node1, mid) and
186-
simpleLocalFlowStep(mid, node2) and
187-
not mid instanceof CastNode
188-
)
189-
}
190-
191-
pragma[nomagic]
192-
predicate localFlowBigStep(Node node1, Node node2) {
193-
localFlowStepPlus(node1, node2) and
194-
localFlowExit(node2)
195-
}
196-
}
197-
198150
/**
199151
* The final flow-through calculation:
200152
*
@@ -234,7 +186,7 @@ private module Cached {
234186
// local flow
235187
exists(Node mid |
236188
parameterValueFlow(p, mid, read) and
237-
LocalFlowBigStep::localFlowBigStep(mid, node)
189+
simpleLocalFlowStep(mid, node)
238190
)
239191
or
240192
// read
@@ -246,16 +198,23 @@ private module Cached {
246198
compatibleTypes(getNodeType(p), read.getContainerType())
247199
)
248200
or
201+
parameterValueFlow0_0(TReadStepTypesNone(), p, node, read)
202+
}
203+
204+
pragma[nomagic]
205+
private predicate parameterValueFlow0_0(
206+
ReadStepTypesOption mustBeNone, ParameterNode p, Node node, ReadStepTypesOption read
207+
) {
249208
// flow through: no prior read
250209
exists(ArgumentNode arg |
251-
parameterValueFlowArg(p, arg, TReadStepTypesNone()) and
210+
parameterValueFlowArg(p, arg, mustBeNone) and
252211
argumentValueFlowsThrough(arg, read, node)
253212
)
254213
or
255214
// flow through: no read inside method
256215
exists(ArgumentNode arg |
257216
parameterValueFlowArg(p, arg, read) and
258-
argumentValueFlowsThrough(arg, TReadStepTypesNone(), node)
217+
argumentValueFlowsThrough(arg, mustBeNone, node)
259218
)
260219
}
261220

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

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -147,54 +147,6 @@ private module Cached {
147147
}
148148
}
149149

150-
private module LocalFlowBigStep {
151-
private predicate localFlowEntry(Node n) {
152-
Cand::cand(_, n) and
153-
(
154-
n instanceof ParameterNode or
155-
n instanceof OutNode or
156-
readStep(_, _, n) or
157-
n instanceof CastNode
158-
)
159-
}
160-
161-
private predicate localFlowExit(Node n) {
162-
Cand::cand(_, n) and
163-
(
164-
n instanceof ArgumentNode
165-
or
166-
n instanceof ReturnNode
167-
or
168-
readStep(n, _, _)
169-
or
170-
n instanceof CastNode
171-
or
172-
n =
173-
any(PostUpdateNode pun | Cand::parameterValueFlowsToPreUpdateCand(_, pun))
174-
.getPreUpdateNode()
175-
)
176-
}
177-
178-
pragma[nomagic]
179-
private predicate localFlowStepPlus(Node node1, Node node2) {
180-
localFlowEntry(node1) and
181-
simpleLocalFlowStep(node1, node2) and
182-
node1 != node2
183-
or
184-
exists(Node mid |
185-
localFlowStepPlus(node1, mid) and
186-
simpleLocalFlowStep(mid, node2) and
187-
not mid instanceof CastNode
188-
)
189-
}
190-
191-
pragma[nomagic]
192-
predicate localFlowBigStep(Node node1, Node node2) {
193-
localFlowStepPlus(node1, node2) and
194-
localFlowExit(node2)
195-
}
196-
}
197-
198150
/**
199151
* The final flow-through calculation:
200152
*
@@ -234,7 +186,7 @@ private module Cached {
234186
// local flow
235187
exists(Node mid |
236188
parameterValueFlow(p, mid, read) and
237-
LocalFlowBigStep::localFlowBigStep(mid, node)
189+
simpleLocalFlowStep(mid, node)
238190
)
239191
or
240192
// read
@@ -246,16 +198,23 @@ private module Cached {
246198
compatibleTypes(getNodeType(p), read.getContainerType())
247199
)
248200
or
201+
parameterValueFlow0_0(TReadStepTypesNone(), p, node, read)
202+
}
203+
204+
pragma[nomagic]
205+
private predicate parameterValueFlow0_0(
206+
ReadStepTypesOption mustBeNone, ParameterNode p, Node node, ReadStepTypesOption read
207+
) {
249208
// flow through: no prior read
250209
exists(ArgumentNode arg |
251-
parameterValueFlowArg(p, arg, TReadStepTypesNone()) and
210+
parameterValueFlowArg(p, arg, mustBeNone) and
252211
argumentValueFlowsThrough(arg, read, node)
253212
)
254213
or
255214
// flow through: no read inside method
256215
exists(ArgumentNode arg |
257216
parameterValueFlowArg(p, arg, read) and
258-
argumentValueFlowsThrough(arg, TReadStepTypesNone(), node)
217+
argumentValueFlowsThrough(arg, mustBeNone, node)
259218
)
260219
}
261220

csharp/ql/src/semmle/code/csharp/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -147,54 +147,6 @@ private module Cached {
147147
}
148148
}
149149

150-
private module LocalFlowBigStep {
151-
private predicate localFlowEntry(Node n) {
152-
Cand::cand(_, n) and
153-
(
154-
n instanceof ParameterNode or
155-
n instanceof OutNode or
156-
readStep(_, _, n) or
157-
n instanceof CastNode
158-
)
159-
}
160-
161-
private predicate localFlowExit(Node n) {
162-
Cand::cand(_, n) and
163-
(
164-
n instanceof ArgumentNode
165-
or
166-
n instanceof ReturnNode
167-
or
168-
readStep(n, _, _)
169-
or
170-
n instanceof CastNode
171-
or
172-
n =
173-
any(PostUpdateNode pun | Cand::parameterValueFlowsToPreUpdateCand(_, pun))
174-
.getPreUpdateNode()
175-
)
176-
}
177-
178-
pragma[nomagic]
179-
private predicate localFlowStepPlus(Node node1, Node node2) {
180-
localFlowEntry(node1) and
181-
simpleLocalFlowStep(node1, node2) and
182-
node1 != node2
183-
or
184-
exists(Node mid |
185-
localFlowStepPlus(node1, mid) and
186-
simpleLocalFlowStep(mid, node2) and
187-
not mid instanceof CastNode
188-
)
189-
}
190-
191-
pragma[nomagic]
192-
predicate localFlowBigStep(Node node1, Node node2) {
193-
localFlowStepPlus(node1, node2) and
194-
localFlowExit(node2)
195-
}
196-
}
197-
198150
/**
199151
* The final flow-through calculation:
200152
*
@@ -234,7 +186,7 @@ private module Cached {
234186
// local flow
235187
exists(Node mid |
236188
parameterValueFlow(p, mid, read) and
237-
LocalFlowBigStep::localFlowBigStep(mid, node)
189+
simpleLocalFlowStep(mid, node)
238190
)
239191
or
240192
// read
@@ -246,16 +198,23 @@ private module Cached {
246198
compatibleTypes(getNodeType(p), read.getContainerType())
247199
)
248200
or
201+
parameterValueFlow0_0(TReadStepTypesNone(), p, node, read)
202+
}
203+
204+
pragma[nomagic]
205+
private predicate parameterValueFlow0_0(
206+
ReadStepTypesOption mustBeNone, ParameterNode p, Node node, ReadStepTypesOption read
207+
) {
249208
// flow through: no prior read
250209
exists(ArgumentNode arg |
251-
parameterValueFlowArg(p, arg, TReadStepTypesNone()) and
210+
parameterValueFlowArg(p, arg, mustBeNone) and
252211
argumentValueFlowsThrough(arg, read, node)
253212
)
254213
or
255214
// flow through: no read inside method
256215
exists(ArgumentNode arg |
257216
parameterValueFlowArg(p, arg, read) and
258-
argumentValueFlowsThrough(arg, TReadStepTypesNone(), node)
217+
argumentValueFlowsThrough(arg, mustBeNone, node)
259218
)
260219
}
261220

java/ql/src/semmle/code/java/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -147,54 +147,6 @@ private module Cached {
147147
}
148148
}
149149

150-
private module LocalFlowBigStep {
151-
private predicate localFlowEntry(Node n) {
152-
Cand::cand(_, n) and
153-
(
154-
n instanceof ParameterNode or
155-
n instanceof OutNode or
156-
readStep(_, _, n) or
157-
n instanceof CastNode
158-
)
159-
}
160-
161-
private predicate localFlowExit(Node n) {
162-
Cand::cand(_, n) and
163-
(
164-
n instanceof ArgumentNode
165-
or
166-
n instanceof ReturnNode
167-
or
168-
readStep(n, _, _)
169-
or
170-
n instanceof CastNode
171-
or
172-
n =
173-
any(PostUpdateNode pun | Cand::parameterValueFlowsToPreUpdateCand(_, pun))
174-
.getPreUpdateNode()
175-
)
176-
}
177-
178-
pragma[nomagic]
179-
private predicate localFlowStepPlus(Node node1, Node node2) {
180-
localFlowEntry(node1) and
181-
simpleLocalFlowStep(node1, node2) and
182-
node1 != node2
183-
or
184-
exists(Node mid |
185-
localFlowStepPlus(node1, mid) and
186-
simpleLocalFlowStep(mid, node2) and
187-
not mid instanceof CastNode
188-
)
189-
}
190-
191-
pragma[nomagic]
192-
predicate localFlowBigStep(Node node1, Node node2) {
193-
localFlowStepPlus(node1, node2) and
194-
localFlowExit(node2)
195-
}
196-
}
197-
198150
/**
199151
* The final flow-through calculation:
200152
*
@@ -234,7 +186,7 @@ private module Cached {
234186
// local flow
235187
exists(Node mid |
236188
parameterValueFlow(p, mid, read) and
237-
LocalFlowBigStep::localFlowBigStep(mid, node)
189+
simpleLocalFlowStep(mid, node)
238190
)
239191
or
240192
// read
@@ -246,16 +198,23 @@ private module Cached {
246198
compatibleTypes(getNodeType(p), read.getContainerType())
247199
)
248200
or
201+
parameterValueFlow0_0(TReadStepTypesNone(), p, node, read)
202+
}
203+
204+
pragma[nomagic]
205+
private predicate parameterValueFlow0_0(
206+
ReadStepTypesOption mustBeNone, ParameterNode p, Node node, ReadStepTypesOption read
207+
) {
249208
// flow through: no prior read
250209
exists(ArgumentNode arg |
251-
parameterValueFlowArg(p, arg, TReadStepTypesNone()) and
210+
parameterValueFlowArg(p, arg, mustBeNone) and
252211
argumentValueFlowsThrough(arg, read, node)
253212
)
254213
or
255214
// flow through: no read inside method
256215
exists(ArgumentNode arg |
257216
parameterValueFlowArg(p, arg, read) and
258-
argumentValueFlowsThrough(arg, TReadStepTypesNone(), node)
217+
argumentValueFlowsThrough(arg, mustBeNone, node)
259218
)
260219
}
261220

0 commit comments

Comments
 (0)