Skip to content

Commit 88eed59

Browse files
committed
wip
1 parent 7f1898b commit 88eed59

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

rust/ql/lib/codeql/rust/controlflow/internal/CfgNodes.qll

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,29 +72,64 @@ class FormatArgsExprChildMapping extends ParentAstNode, CfgImpl::ExprTrees::Form
7272
}
7373

7474
private class ChildMappingImpl extends ChildMapping {
75-
pragma[nomagic]
76-
predicate reachesBasicBlock(AstNode parent, AstNode child, CfgNode cfn, BasicBlock bb) {
75+
private CfgNode getRelevantChildDesug(AstNode parent, AstNode child) {
7776
this.relevantChild(parent, child) and
78-
cfn.getAstNode() = parent and
79-
bb.getANode() = cfn
77+
result = CfgNodesInput::getDesugared(child).getACfgNode()
78+
}
79+
80+
pragma[nomagic]
81+
predicate reachesBasicBlock1(AstNode parent, AstNode child, CfgNode cfnChild, BasicBlock bb) {
82+
cfnChild = this.getRelevantChildDesug(parent, child) and
83+
bb.getANode() = cfnChild
84+
or
85+
exists(BasicBlock bb0 |
86+
cfnChild = this.getRelevantChildDesug(parent, child) and
87+
bb0.getANode() = cfnChild and
88+
not bb0.getANode().getAstNode() = parent and
89+
if isPostOrder(parent) then bb = bb0.getASuccessor() else bb = bb0.getAPredecessor()
90+
)
8091
or
8192
if isPostOrder(parent)
8293
then
8394
exists(BasicBlock mid |
84-
this.reachesBasicBlock(parent, child, cfn, mid) and
85-
bb = mid.getAPredecessor() and
86-
not mid.getANode().getAstNode() = child
95+
this.reachesBasicBlock1(parent, child, cfnChild, mid) and
96+
bb = mid.getASuccessor() and
97+
not mid.getANode().getAstNode() = parent and
98+
not mid.getANode() = this.getRelevantChildDesug(parent, _)
8799
)
88100
else
89101
exists(BasicBlock mid |
90-
this.reachesBasicBlock(parent, child, cfn, mid) and
91-
bb = mid.getASuccessor() and
92-
not mid.getANode().getAstNode() = child
102+
this.reachesBasicBlock1(parent, child, cfnChild, mid) and
103+
bb = mid.getAPredecessor() and
104+
not mid.getANode().getAstNode() = parent and
105+
not mid.getANode() = this.getRelevantChildDesug(parent, _)
106+
)
107+
}
108+
109+
pragma[nomagic]
110+
predicate reachesBasicBlock2(AstNode parent, CfgNode cfnParent, AstNode child, CfgNode cfnChild) {
111+
exists(BasicBlock bb |
112+
this.reachesBasicBlock1(parent, child, cfnChild, bb) and
113+
cfnParent.getAstNode() = parent
114+
|
115+
cfnParent = bb.getANode()
116+
or
117+
if isPostOrder(parent)
118+
then cfnParent = bb.getASuccessor().getANode()
119+
else cfnParent = bb.getAPredecessor().getANode()
120+
)
121+
or
122+
exists(AstNode otherChild, CfgNode cfnOtherChild |
123+
// cfnOtherChild = this.getRelevantChildDesug(parent, otherChild) and
124+
this.reachesBasicBlock2(parent, cfnParent, otherChild, cfnOtherChild) and
125+
exists(BasicBlock bb |
126+
this.reachesBasicBlock1(parent, child, cfnChild, bb) and
127+
bb.getANode() = cfnOtherChild
93128
)
129+
)
94130
}
95131

96132
override predicate hasCfgChild(AstNode parent, AstNode child, AstCfgNode cfn, AstCfgNode cfnChild) {
97-
this.reachesBasicBlock(parent, child, cfn, cfnChild.getBasicBlock()) and
98-
cfnChild.getAstNode() = CfgNodesInput::getDesugared(child)
133+
this.reachesBasicBlock2(parent, cfn, child, cfnChild)
99134
}
100135
}

0 commit comments

Comments
 (0)