Skip to content

Commit 02e4731

Browse files
committed
wip2
1 parent a974c9f commit 02e4731

File tree

1 file changed

+40
-58
lines changed

1 file changed

+40
-58
lines changed

shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll

+40-58
Original file line numberDiff line numberDiff line change
@@ -2606,23 +2606,6 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26062606
);
26072607
}
26082608

2609-
/**
2610-
* A node where some checking is required, and hence the big-step relation
2611-
* is not allowed to step over.
2612-
*/
2613-
additional class FlowCheckNode extends NodeEx {
2614-
FlowCheckNode() {
2615-
revFlow(this, _, _) and
2616-
(
2617-
castNode(this.asNode()) or
2618-
clearsContentCached(this.asNode(), _) or
2619-
expectsContentCached(this.asNode(), _) or
2620-
neverSkipInPathGraph(this.asNode()) or
2621-
Config::neverSkip(this.asNode())
2622-
)
2623-
}
2624-
}
2625-
26262609
/**
26272610
* Provides a big-step relation for local flow steps.
26282611
*
@@ -2631,6 +2614,23 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26312614
* reachable in this stage.
26322615
*/
26332616
additional module LocalFlowBigStep<LocalFlowBigStepInputSig Input> {
2617+
/**
2618+
* A node where some checking is required, and hence the big-step relation
2619+
* is not allowed to step over.
2620+
*/
2621+
private class FlowCheckNode extends NodeEx {
2622+
FlowCheckNode() {
2623+
revFlow(this, _, _) and
2624+
(
2625+
castNode(this.asNode()) or
2626+
clearsContentCached(this.asNode(), _) or
2627+
expectsContentCached(this.asNode(), _) or
2628+
neverSkipInPathGraph(this.asNode()) or
2629+
Config::neverSkip(this.asNode())
2630+
)
2631+
}
2632+
}
2633+
26342634
private predicate additionalLocalStateStep(
26352635
NodeEx node1, FlowState state1, NodeEx node2, FlowState state2, DataFlowType t,
26362636
LocalCallContext lcc, string label
@@ -2647,7 +2647,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26472647
* Holds if `node` can be the first node in a maximal subsequence of local
26482648
* flow steps in a dataflow path.
26492649
*/
2650-
private predicate localFlowEntry(NodeEx node, FlowState state, Ap ap) {
2650+
predicate localFlowEntry(NodeEx node, FlowState state, Ap ap) {
26512651
revFlow(node, state, ap) and
26522652
(
26532653
sourceNode(node, state)
@@ -2679,7 +2679,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
26792679
* Holds if `node` can be the last node in a maximal subsequence of local
26802680
* flow steps in a dataflow path.
26812681
*/
2682-
private predicate localFlowExit(NodeEx node, FlowState state, Ap ap) {
2682+
predicate localFlowExit(NodeEx node, FlowState state, Ap ap) {
26832683
revFlow(node, pragma[only_bind_into](state), pragma[only_bind_into](ap)) and
26842684
(
26852685
exists(NodeEx next, Ap apNext | revFlow(next, pragma[only_bind_into](state), apNext) |
@@ -3788,7 +3788,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
37883788
import CallContextSensitivity<CallContextSensitivityInput>
37893789
import NoLocalCallContext
37903790

3791-
additional module BigStepInput implements PrevStage::LocalFlowBigStepInputSig {
3791+
private module BigStepInput implements PrevStage::LocalFlowBigStepInputSig {
37923792
bindingset[node1, state1]
37933793
bindingset[node2, state2]
37943794
predicate localStep(
@@ -4409,46 +4409,28 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
44094409
import LocalCallContext
44104410

44114411
private module BigStepInput implements PrevStage::LocalFlowBigStepInputSig {
4412-
private predicate smallStep = Stage3Param::BigStepInput::localStep/8;
4413-
4414-
private predicate localStepCand(
4415-
NodeEx node1, FlowState state1, NodeEx node2, FlowState state2, boolean preservesValue
4416-
) {
4417-
Stage5Param::localStep(node1, state1, _, _, _, _, _, _) and
4418-
smallStep(node1, state1, node2, state2, preservesValue, _, _, _)
4419-
or
4420-
exists(FlowState midState, NodeEx midNode |
4421-
localStepCand(node1, state1, midNode, midState, preservesValue) and
4422-
smallStep(midNode, midState, node2, state2, _, _, _, _) and
4423-
not (
4424-
Stage5Param::localStep(midNode, midState, _, _, _, _, _, _) and
4425-
Stage5Param::localStep(_, _, midNode, midState, _, _, _, _)
4426-
) and
4427-
not midNode instanceof Stage5::FlowCheckNode
4428-
)
4429-
}
4430-
4431-
/**
4432-
* When calculating `localFlowBigStep` based on `Stage5Param::localStep`, which
4433-
* is already a big-step relation, we must be careful to avoid quadratic blowup.
4434-
*
4435-
* This is achieved by restricting `Stage5Param::localStep` to those node pairs
4436-
* reacheable via 1 or more `smallStep`s, where any intermediate node is not
4437-
* already part of `Stage5Param::localStep`.
4438-
*/
4439-
pragma[nomagic]
4440-
predicate localStep(
4441-
NodeEx node1, FlowState state1, NodeEx node2, FlowState state2, boolean preservesValue,
4442-
DataFlowType t, LocalCallContext lcc, string label
4443-
) {
4444-
localStepCand(node1, state1, node2, state2, preservesValue) and
4445-
Stage5Param::localStep(node1, state1, node2, state2, preservesValue, t, lcc, label) and
4446-
PrevStage::revFlow(node1, pragma[only_bind_into](state1), _) and
4447-
PrevStage::revFlow(node2, pragma[only_bind_into](state2), _)
4448-
}
4412+
predicate localStep = Stage5Param::localStep/8;
44494413
}
44504414

4451-
predicate localStep = PrevStage::LocalFlowBigStep<BigStepInput>::localFlowBigStep/8;
4415+
pragma[nomagic]
4416+
predicate localStep(
4417+
NodeEx node1, FlowState state1, NodeEx node2, FlowState state2, boolean preservesValue,
4418+
DataFlowType t, LocalCallContext lcc, string label
4419+
) {
4420+
// The following should be equivalent to
4421+
//
4422+
// ```
4423+
// PrevStage::LocalFlowBigStep<BigStepInput>::localFlowBigStep
4424+
// ```
4425+
//
4426+
// but avoids computing the big-step relation based on an existing big-step
4427+
// releation, which may have worst-case quadratic complexity.
4428+
exists(AccessPathApprox ap |
4429+
BigStepInput::localStep(node1, state1, node2, state2, preservesValue, t, lcc, label) and
4430+
PrevStage::LocalFlowBigStep<BigStepInput>::localFlowEntry(node1, state1, ap) and
4431+
PrevStage::LocalFlowBigStep<BigStepInput>::localFlowExit(node2, state2, ap)
4432+
)
4433+
}
44524434

44534435
bindingset[node, state, t0, ap]
44544436
predicate filter(NodeEx node, FlowState state, Typ t0, Ap ap, Typ t) {

0 commit comments

Comments
 (0)